How to use requestretry - 10 common examples

To help you get started, we’ve selected a few requestretry 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 wp-property / wp-property / test / test-0.js View on Github external
'HTTP request can get [wp-property/composer.json].': function( done ) {
    //console.log( 'test one', 'http://' + module.host + ':3000/' );

    request.get( {
      followRedirect: false,
      timeout: 1000,
      headers: {
        host: process.env.CIRCLE_SHA1 + '-' + process.env.CIRCLE_BUILD_NUM + '.ngrok.io'
      },
      url: module.base_url + '/wp-content/plugins/wp-property-' + process.env.CIRCLE_SHA1 + '/composer.json'
    } , function checkResponse( error, resp, body ) {

      if( error ) {
        done( new Error( 'Can not reach WordPress at [' + module.base_url + '/wp-admin/admin-ajax.php].' ) );
      }
      // console.log( require( 'util' ).inspect( resp.headers, {showHidden: false, depth: 2, colors: true} ) );
      // console.log( 'resp.statusCode', resp.statusCode );

      if( resp.statusCode === 301 ) {
        console.log( "Most likely first time tests are being ran and site is trying to redirect to its default siteurl." );
github ContentMine / getpapers / lib / arxiv.js View on Github external
ArXiv.prototype.pageQuery = function () {
  var arxiv = this

  var thisQueryUrl = arxiv.queryurl

  var pageterm =
    '&start=' + arxiv.iter +
    '&max_results=' + arxiv.pagesize
  thisQueryUrl += pageterm

  log.debug(thisQueryUrl)
  var rq = request.get({url: thisQueryUrl,
    headers: {'User-Agent': config.userAgent}})
  var convertXML2JSON = function (data) {
    // console.log(data.body)
    parseString(data.body, function (err, datum) {
      if (err) throw err
      var cb = arxiv.completeCallback.bind(arxiv, datum)
      cb()
    })
  }
  rq.on('complete', convertXML2JSON)
  rq.on('timeout', arxiv.timeoutCallback)
}
github kermitt2 / biblio-glutton / scripts / dump-istexid-and-other-ids.js View on Github external
function getIstexIdsFromOnePage() {
  	var url = urls.pop();
  	request.get({
    	url: url,
    	maxAttempts: 50,   // (default) try 50 times
    	retryDelay: 10000,  // (default) wait for 10s before trying again
    	retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
  	}, 
  	function (err, res) {
    	if (err) {
      		console.error(err, url);
      		return;
    	}
    	var json = JSON.parse(res.body);
 		if (json && json.hits) {
      		json.hits.forEach(function (doc) {
	        	var jsonRes = {
	          		corpusName: doc.corpusName,
	          		istexId: doc.id,
github ContentMine / getpapers / lib / eupmc.js View on Github external
var retryOnHTTPNetOrEuPMCFailure = function (err, response, body) {
    return requestretry.RetryStrategies.HTTPOrNetworkError(err, response, body) ||
            ~body.indexOf('') // hacky way to see if resultsList is empty
  }
github facebookincubator / marketing-data-file-uploader / src / mdfu / EventsUploader.js View on Github external
MODE_OC,
} from './FeedUploaderConstants';
import {getLogger, getLoggerAWS} from './Logger';
import {getValidEvents} from './RequestDataBuilder';
import {
  UNSUPPORTED_MODE,
  ERROR_NO_CA_ID_OR_ACT_ID,
} from './ErrorTypes';

const querystring = require('querystring');
const request = require('requestretry');
const APIErrorTypes = require('./APIErrorTypes');

const MAX_RETRIES = 10;   // Retry 10 times.
const RETRY_DELAY = 5000; // Wait 5s before trying again.
const RETRY_STRATEGY = request.RetryStrategies.HTTPOrNetworkError; // retry on 5xx or network errors.

export const uploadEventsBatch = (
  events: Array,
  postData: string,
  uploadSessionTag: string,
  fileOffset: number,
  configs: FeedUploaderConfigs,
  callback: batchUploadCallbackType,
): void => {
  // Do the real uploading (calling into graph API) if not silent.
  if (configs.silent !== true) {
    getLogger().info(
      `Posting rows ${getBatchSigStr({offset: fileOffset, size: events.length})} to \
${datasetEndpoint(configs)}`
    );
    _postEvents(events, postData, fileOffset, configs, uploadSessionTag, callback);
github gbif / portal16 / app / helpers / request / requestAgents.js View on Github external
// seperate pool for species requests as that API often has outages.
const speciesAgent = new Agent({
  maxSockets: 8000, // Default = Infinity
  maxFreeSockets: 256, // default
  keepAlive: true,
  keepAliveMsecs: 1000
});

let speciesRequest = request.defaults({
  agent: speciesAgent,
  headers: {
    'User-Agent': 'GBIF-portal Occurrence'
  },
  maxAttempts: 1,
  retryDelay: 3000, // in milliseconds
  retryStrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors
  timeout: 45000 // in milliseconds
});

module.exports = {
    standard: stdRequest,
    occurrence: occurrenceRequest,
    species: speciesRequest
};
github taskrabbit / elasticsearch-dump / lib / transports / elasticsearch.js View on Github external
retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
    }

    if (parent.options[`${options.type}SocksProxy`]) {
      Object.assign(defaultOptions,
        elasticsearch.applyProxy(url, parent.options[`${options.type}SocksProxy`], parent.options[`${options.type}SocksPort`]))
    }

    if (this.parent.options.tlsAuth) {
      Object.assign(defaultOptions,
        this.applySSL([`${options.type}-cert`, `${options.type}-key`, `${options.type}-pass`, `${options.type}-ca`]))

      Object.assign(defaultOptions, this.applySSL(['cert', 'key', 'pass', 'ca']))
    }

    this.baseRequest = request.defaults(defaultOptions)
  }
github hdnpt / geartrack / src / skyTracker.js View on Github external
'use strict';

const sprintf = require('sprintf')
const request = require('requestretry').defaults({ maxAttempts: 2, retryDelay: 1000 })
const parser = require('cheerio')
const utils = require('./utils')
const moment = require('moment-timezone')
const zone = "Asia/Hong_Kong" // +8h

const URL = 'http://www.sky56.cn/track/track/result?tracking_number=%s'

const sky = {}

/**
 * Get Sky56 info
 * Supports PQ... and NL... LVS.. SYB.. ids
 * Async
 *
 * @param id
 * @param callback(Error, SkyInfo)
github acoustic-content-samples / wchtools-cli / authoring-api / lib / utils / utils.js View on Github external
const Q = require("q");
const async = require("async");

const ProductName = "IBM Watson Content Hub";
const ProductAbrev = "wchtools";
const ProductVersion = require("../../package.json").version;
const userAgent = ProductAbrev + "/" + ProductVersion;

const i18nModule = require("i18n-2");
const i18n = getI18N(__dirname, ".json", "en");
const vPath = new RegExp('[?<>*|"]');
const loggers = {};
let httplang;

// Enable the request module cookie jar so cookies can be shared across response, request with this request wrapper
const requestWrapper = require("requestretry").defaults({jar: true});

// Expose the default retry strategy for detecting retryable network errors.
const retryNetworkErrors = require("requestretry").RetryStrategies.NetworkError;

/**
 * Get the object that is used to localize strings.
 *
 * @param directory the directory that the search for the nls directory starts from, it looks up the tree for the nls directory
 * @param extension the extension of the file with localizations. Default to .json if not passed
 * @param defaultLocale the local to use as a default. en is used if not set
 *
 * @returns {Object}
 */
function getI18N (directory, extension, defaultLocale) {
    let dir = directory;
    while (dir && !fs.existsSync(dir + "/nls")) {
github hdnpt / geartrack / src / correosOldTracker.js View on Github external
'use strict';

const request = require('requestretry').defaults({timeout: 10000, maxAttempts: 2, retryDelay: 500})
const parser = require('cheerio')
const utils = require('./utils')
const sprintf = require('sprintf')
const moment = require('moment-timezone')
const zone = "Europe/Madrid" // +1h

const URL = 'https://www.correosexpress.com/web/correosexpress/envios4?param=%s;%s'

const correos = {}

/**
 * Get correos info
 * Scraps the Correos Express website
 * Async
 *
 * Design changes may break this code!!

requestretry

request-retry wrap nodejs request to retry http(s) requests in case of error

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis

Similar packages