diff options
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/utils.js b/src/utils.js index d6b26db4b..dda6c7a0a 100644 --- a/src/utils.js +++ b/src/utils.js | |||
@@ -1,6 +1,7 @@ | |||
1 | ;(function () { | 1 | ;(function () { |
2 | 'use strict' | 2 | 'use strict' |
3 | 3 | ||
4 | var async = require('async') | ||
4 | var config = require('config') | 5 | var config = require('config') |
5 | var crypto = require('crypto') | 6 | var crypto = require('crypto') |
6 | var fs = require('fs') | 7 | var fs = require('fs') |
@@ -30,14 +31,15 @@ | |||
30 | } | 31 | } |
31 | 32 | ||
32 | logger.debug('Sending informations to %s.', to_pod.url, { params: params }) | 33 | logger.debug('Sending informations to %s.', to_pod.url, { params: params }) |
34 | // Default 10 but in tests we want to be faster | ||
35 | var retries = utils.isTestInstance() ? 2 : 10 | ||
33 | 36 | ||
34 | // Replay 15 times, with factor 3 | ||
35 | replay( | 37 | replay( |
36 | request.post(params, function (err, response, body) { | 38 | request.post(params, function (err, response, body) { |
37 | callbackEach(err, response, body, to_pod.url) | 39 | callbackEach(err, response, body, to_pod) |
38 | }), | 40 | }), |
39 | { | 41 | { |
40 | retries: 10, | 42 | retries: retries, |
41 | factor: 3, | 43 | factor: 3, |
42 | maxTimeout: Infinity, | 44 | maxTimeout: Infinity, |
43 | errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ] | 45 | errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ] |
@@ -68,7 +70,13 @@ | |||
68 | } | 70 | } |
69 | 71 | ||
70 | // Make a request for each pod | 72 | // Make a request for each pod |
71 | for (var pod of pods) { | 73 | async.each(pods, function (pod, callback_each_async) { |
74 | function callbackEachRetryRequest (err, response, body, pod) { | ||
75 | callbackEach(err, response, body, pod, function () { | ||
76 | callback_each_async() | ||
77 | }) | ||
78 | } | ||
79 | |||
72 | var params = { | 80 | var params = { |
73 | url: pod.url + all_data.path, | 81 | url: pod.url + all_data.path, |
74 | method: all_data.method | 82 | method: all_data.method |
@@ -93,20 +101,18 @@ | |||
93 | key: passwordEncrypted | 101 | key: passwordEncrypted |
94 | } | 102 | } |
95 | 103 | ||
96 | makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEach) | 104 | makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEachRetryRequest) |
97 | }) | 105 | }) |
98 | })(crt, params, url, pod, signature) | 106 | })(crt, params, url, pod, signature) |
99 | } else { | 107 | } else { |
100 | params.json = { data: all_data.data } | 108 | params.json = { data: all_data.data } |
101 | makeRetryRequest(params, url, pod, signature, callbackEach) | 109 | makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) |
102 | } | 110 | } |
103 | } else { | 111 | } else { |
104 | logger.debug('Make a GET/DELETE request') | 112 | logger.debug('Make a GET/DELETE request') |
105 | makeRetryRequest(params, url, pod, signature, callbackEach) | 113 | makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) |
106 | } | 114 | } |
107 | } | 115 | }, callback) |
108 | |||
109 | return callback() | ||
110 | } | 116 | } |
111 | 117 | ||
112 | utils.certsExist = function (callback) { | 118 | utils.certsExist = function (callback) { |
@@ -192,5 +198,9 @@ | |||
192 | process.kill(-webtorrent_process.pid) | 198 | process.kill(-webtorrent_process.pid) |
193 | } | 199 | } |
194 | 200 | ||
201 | utils.isTestInstance = function () { | ||
202 | return (process.env.NODE_ENV === 'test') | ||
203 | } | ||
204 | |||
195 | module.exports = utils | 205 | module.exports = utils |
196 | })() | 206 | })() |