-
Notifications
You must be signed in to change notification settings - Fork 9
/
doxbee-sequential-errors.sjs
48 lines (45 loc) · 1.49 KB
/
doxbee-sequential-errors.sjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This file is a port of the benchmark written for bluebird
// https://github.com/petkaantonov/bluebird/tree/master/benchmark/doxbee-sequential-errors
// It requires 'state_machine.js' to be in ../node_modules
require('../lib/fakes');
task upload(stream, idOrPath, tag) {
var blob = blobManager.create(account),
tx = db.begin();
catch (err) {
tx.rollback();
}
blobId <- blob.put(stream);
file <- self.byUuidOrPath(idOrPath).get();
var previousId = file ? file.version : null;
version = {
userAccountId: userAccount.id,
date: new Date(),
blobId: blobId,
creatorId: userAccount.id,
previousId: previousId,
};
version.id = Version.createHash(version);
await Version.insert(version).execWithin(tx);
triggerIntentionalError();
if (!file) {
var splitPath = idOrPath.split('/');
var fileName = splitPath[splitPath.length - 1];
file = {
id: uuid.v1(),
userAccountId: userAccount.id,
name: fileName,
version: version.id
};
query <- self.createQuery(idOrPath, file);
await query.execWithin(tx);
triggerIntentionalError();
}
await FileVersion.insert({fileId: file.id, versionId: version.id})
.execWithin(tx);
triggerIntentionalError();
await File.whereUpdate({id: file.id}, {version: version.id})
.execWithin(tx);
triggerIntentionalError();
tx.commit();
}
module.exports = upload;