aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/utils.js')
-rw-r--r--server/helpers/utils.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index 9f4b14582..a902850cd 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -1,6 +1,7 @@
1'use strict' 1'use strict'
2 2
3const crypto = require('crypto') 3const crypto = require('crypto')
4const retry = require('async/retry')
4 5
5const logger = require('./logger') 6const logger = require('./logger')
6 7
@@ -9,7 +10,8 @@ const utils = {
9 cleanForExit, 10 cleanForExit,
10 generateRandomString, 11 generateRandomString,
11 isTestInstance, 12 isTestInstance,
12 getFormatedObjects 13 getFormatedObjects,
14 transactionRetryer
13} 15}
14 16
15function badRequest (req, res, next) { 17function badRequest (req, res, next) {
@@ -46,6 +48,18 @@ function getFormatedObjects (objects, objectsTotal) {
46 } 48 }
47} 49}
48 50
51function transactionRetryer (func, callback) {
52 retry({
53 times: 5,
54
55 errorFilter: function (err) {
56 const willRetry = (err.name === 'SequelizeDatabaseError')
57 logger.debug('Maybe retrying the transaction function.', { willRetry })
58 return willRetry
59 }
60 }, func, callback)
61}
62
49// --------------------------------------------------------------------------- 63// ---------------------------------------------------------------------------
50 64
51module.exports = utils 65module.exports = utils