diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-17 20:38:45 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-17 20:50:45 +0100 |
commit | 4145c1c68923c13538a5b60d1b384037d0dded9d (patch) | |
tree | 36471645006f47d1118fcba59a4f5d3e84598856 /server/helpers | |
parent | 98dffd102ef76872f027fedfc55cc0dc824b5bad (diff) | |
download | PeerTube-4145c1c68923c13538a5b60d1b384037d0dded9d.tar.gz PeerTube-4145c1c68923c13538a5b60d1b384037d0dded9d.tar.zst PeerTube-4145c1c68923c13538a5b60d1b384037d0dded9d.zip |
Server: transaction refractoring
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/database-utils.js | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/server/helpers/database-utils.js b/server/helpers/database-utils.js index 046717517..6fe7e99aa 100644 --- a/server/helpers/database-utils.js +++ b/server/helpers/database-utils.js | |||
@@ -6,9 +6,27 @@ const db = require('../initializers/database') | |||
6 | const logger = require('./logger') | 6 | const logger = require('./logger') |
7 | 7 | ||
8 | const utils = { | 8 | const utils = { |
9 | commitTransaction, | ||
9 | retryTransactionWrapper, | 10 | retryTransactionWrapper, |
10 | transactionRetryer, | 11 | rollbackTransaction, |
11 | startSerializableTransaction | 12 | startSerializableTransaction, |
13 | transactionRetryer | ||
14 | } | ||
15 | |||
16 | function commitTransaction (t, callback) { | ||
17 | return t.commit().asCallback(callback) | ||
18 | } | ||
19 | |||
20 | function rollbackTransaction (err, t, callback) { | ||
21 | // Try to rollback transaction | ||
22 | if (t) { | ||
23 | // Do not catch err, report the original one | ||
24 | t.rollback().asCallback(function () { | ||
25 | return callback(err) | ||
26 | }) | ||
27 | } else { | ||
28 | return callback(err) | ||
29 | } | ||
12 | } | 30 | } |
13 | 31 | ||
14 | // { arguments, errorMessage } | 32 | // { arguments, errorMessage } |