aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-15 19:13:16 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-15 19:13:16 +0100
commitd6a5b018b89f9d2569ca7435b0e270095c93cc17 (patch)
treec7f24df4853ad2de7934dfa926ef915222a38277 /server/helpers
parenta7721e62c028f54c1d165b53ac1a7a60b6c3b82e (diff)
downloadPeerTube-d6a5b018b89f9d2569ca7435b0e270095c93cc17.tar.gz
PeerTube-d6a5b018b89f9d2569ca7435b0e270095c93cc17.tar.zst
PeerTube-d6a5b018b89f9d2569ca7435b0e270095c93cc17.zip
Server: retryer transaction wrapper refractoring
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/utils.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index a902850cd..fb4dd08cc 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -11,6 +11,7 @@ const utils = {
11 generateRandomString, 11 generateRandomString,
12 isTestInstance, 12 isTestInstance,
13 getFormatedObjects, 13 getFormatedObjects,
14 retryWrapper,
14 transactionRetryer 15 transactionRetryer
15} 16}
16 17
@@ -48,6 +49,25 @@ function getFormatedObjects (objects, objectsTotal) {
48 } 49 }
49} 50}
50 51
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
51function transactionRetryer (func, callback) { 71function transactionRetryer (func, callback) {
52 retry({ 72 retry({
53 times: 5, 73 times: 5,