# charlie

> Charlie knows

Latest version **0.0.5** (published 2012-05-21) · 0 weekly downloads

## Install

```sh
npm install charlie
pnpm add charlie
yarn add charlie
bun add charlie
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2012-05-21 |
| First published | 2012-05-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | ql.io |
| Maintainers | s3u |

## Links

- npm: https://www.npmjs.com/package/charlie
- Repository: https://github.com/ql-io/charlie
- npm.io page: https://npm.io/package/charlie

## Recent versions

- 0.0.5 (latest) — 2012-05-21
- 0.0.4 — 2012-05-06
- 0.0.3 — 2012-05-03
- 0.0.2 — 2012-05-03
- 0.0.1 — 2012-05-03

## README

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](http://dthain.blogspot.com/2009/02/exponential-backoff-in-distributed.html).

This module applies skips upto three failures before starting the backoff.

![Travis status](https://secure.travis-ci.org/ql-io/charlie.png)

## 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);

---
_Source: https://npm.io/package/charlie · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
