How to use the async.retry function in async

To help you get started, we’ve selected a few async examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kuzzleio / kuzzle / features / step_definitions / bulk.js View on Github external
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();
  });
});
github dudleycarr / nsqjs / lib / lookupd.js View on Github external
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)) {
github bitpay / insight-api / regtest / reorg.js View on Github external
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);
};
github bitpay / bwdb / regtest / gettransactionslist.js View on Github external
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) {
github bitpay / bwdb / lib / utils.js View on Github external
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);
};
github nodejs / github-bot / lib / node-repo.js View on Github external
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)
  })
}
github kuzzleio / kuzzle / features / step_definitions / validation.js View on Github external
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();
  });
});
github GaurangBhatt / BeamlineJS / beamline / s3Uploader.js View on Github external
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);
  }
}
github LiskHQ / lisk-sdk-examples / framework / src / modules / chain / submodules / loader.js View on Github external
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);
				},
			},
github cloudsploit / scans / helpers / aws / functions.js View on Github external
//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);
        });
    }
}