diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/helpers/database-utils.ts | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
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) |