aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/database-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r--server/helpers/database-utils.ts13
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 @@
1import * 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
2import * as retry from 'async/retry' 3import * as retry from 'async/retry'
3 4
4import { database as db } from '../initializers/database' 5import { database as db } from '../initializers/database'
5import { logger } from './logger' 6import { logger } from './logger'
6 7
7function commitTransaction (t, callback) { 8function commitTransaction (t: Sequelize.Transaction, callback: (err: Error) => void) {
8 return t.commit().asCallback(callback) 9 return t.commit().asCallback(callback)
9} 10}
10 11
11function rollbackTransaction (err, t, callback) { 12function 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 } 24type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] }
24function retryTransactionWrapper (functionToRetry, options, finalCallback) { 25function 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
42function transactionRetryer (func, callback) { 43function 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
54function startSerializableTransaction (callback) { 55function 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)