diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-15 19:13:16 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-15 19:13:16 +0100 |
commit | d6a5b018b89f9d2569ca7435b0e270095c93cc17 (patch) | |
tree | c7f24df4853ad2de7934dfa926ef915222a38277 /server/helpers/utils.js | |
parent | a7721e62c028f54c1d165b53ac1a7a60b6c3b82e (diff) | |
download | PeerTube-d6a5b018b89f9d2569ca7435b0e270095c93cc17.tar.gz PeerTube-d6a5b018b89f9d2569ca7435b0e270095c93cc17.tar.zst PeerTube-d6a5b018b89f9d2569ca7435b0e270095c93cc17.zip |
Server: retryer transaction wrapper refractoring
Diffstat (limited to 'server/helpers/utils.js')
-rw-r--r-- | server/helpers/utils.js | 20 |
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 } | ||
53 | function 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 | |||
51 | function transactionRetryer (func, callback) { | 71 | function transactionRetryer (func, callback) { |
52 | retry({ | 72 | retry({ |
53 | times: 5, | 73 | times: 5, |