aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-15 19:53:11 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-15 19:53:11 +0100
commit4df023f2d4e4ea93d3fbc6010f0460511ba45140 (patch)
tree02f8df3be3d9a3fff943aa186daed22f0825f266 /server/helpers/utils.js
parent9bce75925eb972f7a49c25250e636b7b76734475 (diff)
downloadPeerTube-4df023f2d4e4ea93d3fbc6010f0460511ba45140.tar.gz
PeerTube-4df023f2d4e4ea93d3fbc6010f0460511ba45140.tar.zst
PeerTube-4df023f2d4e4ea93d3fbc6010f0460511ba45140.zip
Server: create transaction refractoring
Diffstat (limited to 'server/helpers/utils.js')
-rw-r--r--server/helpers/utils.js36
1 files changed, 1 insertions, 35 deletions
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index fb4dd08cc..9f4b14582 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -1,7 +1,6 @@
1'use strict' 1'use strict'
2 2
3const crypto = require('crypto') 3const crypto = require('crypto')
4const retry = require('async/retry')
5 4
6const logger = require('./logger') 5const logger = require('./logger')
7 6
@@ -10,9 +9,7 @@ const utils = {
10 cleanForExit, 9 cleanForExit,
11 generateRandomString, 10 generateRandomString,
12 isTestInstance, 11 isTestInstance,
13 getFormatedObjects, 12 getFormatedObjects
14 retryWrapper,
15 transactionRetryer
16} 13}
17 14
18function badRequest (req, res, next) { 15function badRequest (req, res, next) {
@@ -49,37 +46,6 @@ function getFormatedObjects (objects, objectsTotal) {
49 } 46 }
50} 47}
51 48
52// { arguments, errorMessage }
53function retryWrapper (functionToRetry, options, finalCallback) {
54 const args = options.arguments ? options.arguments : []
55
56 utils.transactionRetryer(
57 function (callback) {
58 return functionToRetry.apply(this, args.concat([ callback ]))
59 },
60 function (err) {
61 if (err) {
62 logger.error(options.errorMessage, { error: err })
63 }
64
65 // Do not return the error, continue the process
66 return finalCallback(null)
67 }
68 )
69}
70
71function transactionRetryer (func, callback) {
72 retry({
73 times: 5,
74
75 errorFilter: function (err) {
76 const willRetry = (err.name === 'SequelizeDatabaseError')
77 logger.debug('Maybe retrying the transaction function.', { willRetry })
78 return willRetry
79 }
80 }, func, callback)
81}
82
83// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
84 50
85module.exports = utils 51module.exports = utils