diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/utils.js | 16 |
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 | ||
3 | const crypto = require('crypto') | 3 | const crypto = require('crypto') |
4 | const retry = require('async/retry') | ||
4 | 5 | ||
5 | const logger = require('./logger') | 6 | const 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 | ||
15 | function badRequest (req, res, next) { | 17 | function badRequest (req, res, next) { |
@@ -46,6 +48,18 @@ function getFormatedObjects (objects, objectsTotal) { | |||
46 | } | 48 | } |
47 | } | 49 | } |
48 | 50 | ||
51 | function 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 | ||
51 | module.exports = utils | 65 | module.exports = utils |