Giter VIP home page Giter VIP logo

charlie's Introduction

Charlie is a node module keeps of success and failures of network requests and adises on a delay between attempts using the backoff algorithm described in Exponential Backoff in Distributed Systems.

This module skips upto three failures before starting the backoff.

Travis status

Getting Charlie

npm install charlie

Usage

charlie.ask

Before making a request to an origin, let charlie know. This functiont akes three arguments:

  • keys: An array of keys used to identify the network resource. For HTTP requests, the keys could be the URI of the resource, or the IP address, or the host name etc.
  • minDelay: Minimum backoff delay. As suggested in the blog post above, choose a value under which 99% of requests complete.
  • maxDelay: Maximum backoff delay. Choose an acceptable value based on availability requirements.

This function returns a decision with three fields:

  • state: values are go or nogo
  • count: number of failures so far. The count is reset after a success.
  • delay: currently applied backoff delay

Here is an example.

// Arr is an array of keys used to identify the network resource.
var decision = charlie.ask(arr, minDelay, maxDelay);
if(decision.state === 'go') {
    // make the request
}
else {
    // don't make the request
    console.log('Waiting until ' + decision.delay);
}

charlie.ok

When a request succeeds, tell charlie.

charlie.ok(arr);

charlie.notok

When the request fails, tell charlie any way.

charlie.notok(arr);

charlie.clear

Forget everything about the resource.

charlie.clear(arr);

charlie's People

Stargazers

Isao Yagi avatar node-migrator-bot avatar Philipp Waldmann avatar Jórgos Skettos avatar J. J. Knudsen avatar Ezekiel Templin avatar Andrea Campi avatar Matthew J Carlson avatar

Watchers

James Cloos avatar  avatar

Forkers

s3u vsteam

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.