;(function () {
'use strict'
+ var async = require('async')
var config = require('config')
var crypto = require('crypto')
var fs = require('fs')
var replay = require('request-replay')
var ursa = require('ursa')
+ var constants = require('./constants')
var logger = require('./logger')
var utils = {}
}
}
- logger.debug('Sending informations to %s.', to_pod.url, { params: params })
+ logger.debug('Make retry requests to %s.', to_pod.url)
- // Replay 15 times, with factor 3
replay(
request.post(params, function (err, response, body) {
- callbackEach(err, response, body, to_pod.url)
+ callbackEach(err, response, body, params.url, to_pod)
}),
{
- retries: 10,
+ retries: constants.REQUEST_RETRIES,
factor: 3,
maxTimeout: Infinity,
errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
}
// Make a request for each pod
- for (var pod of pods) {
+ async.each(pods, function (pod, callback_each_async) {
+ function callbackEachRetryRequest (err, response, body, url, pod) {
+ callbackEach(err, response, body, url, pod, function () {
+ callback_each_async()
+ })
+ }
+
var params = {
url: pod.url + all_data.path,
method: all_data.method
// Add data with POST requst ?
if (all_data.method === 'POST' && all_data.data) {
- logger.debug('Make a POST request.')
-
// Encrypt data ?
if (all_data.encrypt === true) {
var crt = ursa.createPublicKey(pod.publicKey)
key: passwordEncrypted
}
- makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEach)
+ makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEachRetryRequest)
})
})(crt, params, url, pod, signature)
} else {
params.json = { data: all_data.data }
- makeRetryRequest(params, url, pod, signature, callbackEach)
+ makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
} else {
- logger.debug('Make a GET/DELETE request')
- makeRetryRequest(params, url, pod, signature, callbackEach)
+ makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
- }
-
- return callback()
+ }, callback)
}
utils.certsExist = function (callback) {