Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
callbackAsyncParallel();
});
}
}, 1, function (error) {
// Only when we have response from async.parallelLimit we can stop retry by calling callbackAsync
if (error) {
callbackAsync(error);
return false;
}
callbackAsync();
}); // end async.parallel
}, 20); // end setTimeout
}; // end method main
async.retry(20, main.bind(this), function (err) {
if (err) {
if (err.message) {
err = err.message;
}
callback(new Error(err));
return false;
}
callback();
});
});
function lookupdRequest (url, callback) {
// All responses are JSON
const options = {
url,
method: 'GET',
json: true,
timeout: 2000
}
const requestWithRetry = cb => request(options, cb)
const retryOptions = { times: 3, interval: 500 }
async.retry(retryOptions, requestWithRetry, (err, response, data = {}) => {
if (err) {
log(`lookup failed for ${url}`)
return callback(null, [])
}
const statusCode = (data ? data.status_code : null) || response.statusCode
if (statusCode !== 200) {
log(`lookup failed for ${url}. Returned status code: ${statusCode}.`)
return callback(null, [])
}
try {
let { producers } = data
// Support pre version 1.x lookupd response.
if (!_.isEmpty(data.data)) {
var waitForBlocksGenerated = function(callback) {
var httpOpts = {
hostname: 'localhost',
port: 53001,
path: '/api/status',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
async.retry({ interval: 1000, times: 100 }, function(next) {
request(httpOpts, function(err, data) {
if (err) {
return next(err);
}
if (data.info.blocks !== blocksGenerated) {
return next(data);
}
next();
});
}, callback);
};
var syncedHandler = function(height) {
if (height >= startingNumOfBlocks) {
server.node.services.bitcoind.removeListener('synced', syncedHandler);
var imported;
async.retry({times: 5, interval: 2000}, function(next) {
client.getInfo(function(err, response) {
if(err) {
return next('try again');
}
if (parseInt(response.headers['x-bitcoin-height']) >= startingNumOfBlocks) {
return next(null, response);
}
//do this only once!
if (!imported) {
imported = true;
testUtils.importWalletDat({
client: client,
config: config,
path: configPath + '/bitcoin/regtest/wallet.dat'
}, function(err, response) {
if (err) {
exports.tryAllClients = function(obj, func, options, callback) {
if (_.isFunction(options)) {
callback = options;
options = {};
}
var clientIndex = obj._clientsIndex;
var retry = function(done) {
var client = obj._clients[clientIndex];
clientIndex = (clientIndex + 1) % obj._clients.length;
func(client, done);
};
async.retry({times: obj._clients.length, interval: options.interval || 1000}, retry, callback);
};
function resolveLabelsThenUpdatePr (options) {
options.logger.debug('Fetching PR files for labelling')
const getFiles = (cb) => {
githubClient.pullRequests.getFiles({
owner: options.owner,
repo: options.repo,
number: options.prId
}, cb)
}
retry({ times: 5, interval: fiveSeconds }, getFiles, (err, res) => {
if (err) {
return options.logger.error(err, 'Error retrieving files from GitHub')
}
const filepathsChanged = res.data.map((fileMeta) => fileMeta.filename)
const resolvedLabels = resolveLabels(filepathsChanged, options.baseBranch)
fetchExistingThenUpdatePr(options, resolvedLabels)
})
}
if (response.result.hits === undefined || response.result.total === undefined) {
return callbackAsync(new Error('Malformed search results'));
}
if (response.result.hits.length !== hits || response.result.total !== hits) {
return callbackAsync(new Error(`Wrong number of results. Expected: ${hits}, got ${response.result.hits.length} (or ${response.result.total})`));
}
this.scrollId = response.result.scrollId;
callbackAsync();
})
.catch(err => callbackAsync(err));
}, 200);
};
async.retry(20, search.bind(this), function (err) {
if (err) {
return callback(new Error(err));
}
callback();
});
});
function uploadFile(uploadCb) {
var fileName = path.basename(absoluteFilePath);
var stats = fs.statSync(absoluteFilePath);
var fileSizeInBytes = stats["size"];
if(fileSizeInBytes < (1024*1024*5)) {
async.retry((retryCb) => {
fs.readFile(absoluteFilePath, (err, fileData) => {
s3.putObject({
Bucket: bucketName,
Key: fileName,
Body: fileData,
ServerSideEncryption: 'AES256'
}, retryCb);
});
}, uploadCb);
}else{
uploadMultipart(uploadCb);
}
}
loadSignatures(seriesCb) {
if (__private.loaded) {
return async.retry(
__private.retries,
__private.getSignaturesFromNetwork,
err => {
if (err) {
library.logger.error('Signatures loader', err);
}
return setImmediate(seriesCb);
}
);
}
return setImmediate(seriesCb);
},
},
//callback(CREDENTIAL_REPORT_ERROR);
callback('Error downloading report');
}
});
} else {
var pingCredentialReport = function(pingCb, pingResults) {
iam.getCredentialReport(function(getErr, getData) {
if (getErr || !getData || !getData.Content) {
return pingCb('Error waiting for credential report: ' + (getErr ? getErr : 'No data returned from AWS after 60 seconds.'));
}
pingCb(null, getData);
});
};
async.retry({times: 20, interval: 3000}, pingCredentialReport, function(reportErr, reportData){
if (reportErr || !reportData) {
//CREDENTIAL_REPORT_ERROR = 'Error downloading report';
//return callback(CREDENTIAL_REPORT_ERROR);
return callback('Error downloading report');
}
//CREDENTIAL_REPORT_DATA = reportData;
//callback(null, CREDENTIAL_REPORT_DATA);
callback(null, reportData);
});
}
}