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:
parent
a7721e62c0
commit
d6a5b018b8
4 changed files with 51 additions and 50 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue