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.ts14
1 files changed, 5 insertions, 9 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index e174dc3e9..987e42eb0 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -8,13 +8,11 @@ type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[]
8function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, options: RetryTransactionWrapperOptions) { 8function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, options: RetryTransactionWrapperOptions) {
9 const args = options.arguments ? options.arguments : [] 9 const args = options.arguments ? options.arguments : []
10 10
11 return transactionRetryer( 11 return transactionRetryer(callback => {
12 function (callback) { 12 functionToRetry.apply(this, args)
13 functionToRetry.apply(this, args)
14 .then(result => callback(null, result)) 13 .then(result => callback(null, result))
15 .catch(err => callback(err)) 14 .catch(err => callback(err))
16 } 15 })
17 )
18 .catch(err => { 16 .catch(err => {
19 // Do not throw the error, continue the process 17 // Do not throw the error, continue the process
20 logger.error(options.errorMessage, err) 18 logger.error(options.errorMessage, err)
@@ -26,14 +24,12 @@ function transactionRetryer (func: Function) {
26 retry({ 24 retry({
27 times: 5, 25 times: 5,
28 26
29 errorFilter: function (err) { 27 errorFilter: err => {
30 const willRetry = (err.name === 'SequelizeDatabaseError') 28 const willRetry = (err.name === 'SequelizeDatabaseError')
31 logger.debug('Maybe retrying the transaction function.', { willRetry }) 29 logger.debug('Maybe retrying the transaction function.', { willRetry })
32 return willRetry 30 return willRetry
33 } 31 }
34 }, func, function (err) { 32 }, func, err => err ? rej(err) : res())
35 err ? rej(err) : res()
36 })
37 }) 33 })
38} 34}
39 35