Code Monkey home page Code Monkey logo

repeatable-request's Introduction

repeatable-request

Build Status Coverage Status Code Climate

dependencies Status devDependencies Status

To repeat a request until a condition is met. Used for retrying request whenever a retryable error is raised.

Installation

$ npm install --save repeatable-request

or with yarn

$ yarn add --dev repeatable-request

Usage

var repeatableRequest = require('repeatable-request');

var sendRequest = function() {
}

// Arguments are: contextArgs, args, done
repeatableRequest({
  sendRequest: sendRequest, // Required
  isRetryable: function (error, data) {
    // You can put any check here, Return true to sendRequest again
    return error.retryable === true;
  },
  backoffRange: {
    start: 200,
    end: 500,
  },
  maxRetryCount: 2,
}, { key: 'arguments passed as first parameter to sendRequest' }, function(error, done) {
  console.log(error, done);
});

Options

Various options can be passed to the first argument of repeatableRequest.

sendRequest (Required)

Method sending request with callback pattern signature

function(args, done);

repeatableRequest takes following arguments:

  • contextArgs
  • args
  • done

Out of these args and done are passed to sendRequest method

isRetryable (Optional)

A function in format function(error, data) {}. If this method returns true then sendRequest is called again. Default:

function(error) {
  return error && error.retryable === true;
}

backoffRange { start, end } (Optional)

An object determining minimum and maximum time in milliseconds library should wait before retrying. Any random value b/w start and end is used with setTimeout function to defer retry execution. Default:

{ start: 500, end: 1000 }

maxRetryCount (Optional)

Maximum number of times request can be repeated Default: 3

Retry Exhaust

In case of all retries were exhausted, then last error received will be passed to done function.

repeatable-request's People

Contributors

varunnayal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.