1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Server: retryer transaction wrapper refractoring

This commit is contained in:
Chocobozzz 2017-01-15 19:13:16 +01:00
parent a7721e62c0
commit d6a5b018b8
4 changed files with 51 additions and 50 deletions

View file

@ -11,6 +11,7 @@ const utils = {
generateRandomString,
isTestInstance,
getFormatedObjects,
retryWrapper,
transactionRetryer
}
@ -48,6 +49,25 @@ function getFormatedObjects (objects, objectsTotal) {
}
}
// { arguments, errorMessage }
function retryWrapper (functionToRetry, options, finalCallback) {
const args = options.arguments ? options.arguments : []
utils.transactionRetryer(
function (callback) {
return functionToRetry.apply(this, args.concat([ callback ]))
},
function (err) {
if (err) {
logger.error(options.errorMessage, { error: err })
}
// Do not return the error, continue the process
return finalCallback(null)
}
)
}
function transactionRetryer (func, callback) {
retry({
times: 5,