diff options
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r-- | server/helpers/database-utils.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 4f49c5825..f8ee9a454 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -1,14 +1,15 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
1 | // TODO: import from ES6 when retry typing file will include errorFilter function | 2 | // TODO: import from ES6 when retry typing file will include errorFilter function |
2 | import * as retry from 'async/retry' | 3 | import * as retry from 'async/retry' |
3 | 4 | ||
4 | import { database as db } from '../initializers/database' | 5 | import { database as db } from '../initializers/database' |
5 | import { logger } from './logger' | 6 | import { logger } from './logger' |
6 | 7 | ||
7 | function commitTransaction (t, callback) { | 8 | function commitTransaction (t: Sequelize.Transaction, callback: (err: Error) => void) { |
8 | return t.commit().asCallback(callback) | 9 | return t.commit().asCallback(callback) |
9 | } | 10 | } |
10 | 11 | ||
11 | function rollbackTransaction (err, t, callback) { | 12 | function rollbackTransaction (err: Error, t: Sequelize.Transaction, callback: (err: Error) => void) { |
12 | // Try to rollback transaction | 13 | // Try to rollback transaction |
13 | if (t) { | 14 | if (t) { |
14 | // Do not catch err, report the original one | 15 | // Do not catch err, report the original one |
@@ -20,8 +21,8 @@ function rollbackTransaction (err, t, callback) { | |||
20 | } | 21 | } |
21 | } | 22 | } |
22 | 23 | ||
23 | // { arguments, errorMessage } | 24 | type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } |
24 | function retryTransactionWrapper (functionToRetry, options, finalCallback) { | 25 | function retryTransactionWrapper (functionToRetry: Function, options: RetryTransactionWrapperOptions, finalCallback: Function) { |
25 | const args = options.arguments ? options.arguments : [] | 26 | const args = options.arguments ? options.arguments : [] |
26 | 27 | ||
27 | transactionRetryer( | 28 | transactionRetryer( |
@@ -39,7 +40,7 @@ function retryTransactionWrapper (functionToRetry, options, finalCallback) { | |||
39 | ) | 40 | ) |
40 | } | 41 | } |
41 | 42 | ||
42 | function transactionRetryer (func, callback) { | 43 | function transactionRetryer (func: Function, callback: (err: Error) => void) { |
43 | retry({ | 44 | retry({ |
44 | times: 5, | 45 | times: 5, |
45 | 46 | ||
@@ -51,7 +52,7 @@ function transactionRetryer (func, callback) { | |||
51 | }, func, callback) | 52 | }, func, callback) |
52 | } | 53 | } |
53 | 54 | ||
54 | function startSerializableTransaction (callback) { | 55 | function startSerializableTransaction (callback: (err: Error, t: Sequelize.Transaction) => void) { |
55 | db.sequelize.transaction(/* { isolationLevel: 'SERIALIZABLE' } */).asCallback(function (err, t) { | 56 | db.sequelize.transaction(/* { isolationLevel: 'SERIALIZABLE' } */).asCallback(function (err, t) { |
56 | // We force to return only two parameters | 57 | // We force to return only two parameters |
57 | return callback(err, t) | 58 | return callback(err, t) |