Skip to content

Commit

Permalink
docs(delayStrategy)
Browse files Browse the repository at this point in the history
  • Loading branch information
FGRibreau committed Sep 7, 2016
1 parent fdc72ae commit be1fdc3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

=========================================

[![Build Status](https://img.shields.io/circleci/project/FGRibreau/node-request-retry.svg)](https://circleci.com/gh/FGRibreau/node-request-retry/) [![Coverage Status](https://img.shields.io/coveralls/FGRibreau/node-request-retry/master.svg)](https://coveralls.io/github/FGRibreau/node-request-retry?branch=master) [![Deps]( https://img.shields.io/david/FGRibreau/node-request-retry.svg)](https://david-dm.org/FGRibreau/node-request-retry) [![NPM version](https://img.shields.io/npm/v/requestretry.svg)](http://badge.fury.io/js/requestretry) [![Downloads](http://img.shields.io/npm/dm/requestretry.svg)](https://www.npmjs.com/package/requestretry)
[![Build Status](https://img.shields.io/circleci/project/FGRibreau/node-request-retry.svg)](https://circleci.com/gh/FGRibreau/node-request-retry/) [![Coverage Status](https://img.shields.io/coveralls/FGRibreau/node-request-retry/master.svg)](https://coveralls.io/github/FGRibreau/node-request-retry?branch=master) [![Deps]( https://img.shields.io/david/FGRibreau/node-request-retry.svg)](https://david-dm.org/FGRibreau/node-request-retry) [![NPM version](https://img.shields.io/npm/v/requestretry.svg)](http://badge.fury.io/js/requestretry) [![Downloads](http://img.shields.io/npm/dm/requestretry.svg)](https://www.npmjs.com/package/requestretry)

[![available-for-advisory](https://img.shields.io/badge/available%20for%20consulting%20advisory-yes-ff69b4.svg?)](http://bit.ly/2c7uFJq) ![extra](https://img.shields.io/badge/actively%20maintained-yes-ff69b4.svg)

Expand Down Expand Up @@ -100,10 +100,13 @@ Install with [npm](https://npmjs.org/package/requestretry).

## How to define your own retry strategy

A retry strategy let you specify when request-retry should retry a request

```
/**
* @param {Null | Object} err
* @param {Object} response
* @param {Object} body
* @return {Boolean} true if the request should be retried
*/
function myRetryStrategy(err, response, body){
Expand All @@ -122,11 +125,14 @@ request({

## How to define your own delay strategy

A delay strategy let you specify how long request-retry should wait before trying again the request

```
/**
* @param {Null | Object} err
* @param {Object} response
* @return {Number} number of milliseconds to delay
* @param {Object} body
* @return {Number} number of milliseconds to wait before trying again the request
*/
function myDelayStrategy(err, response, body){
// set delay of retry to a random number between 500 and 3500 ms
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ function Request(url, options, f, retryConfig) {
* @type {Function} (err, response) -> Boolean
*/
this.retryStrategy = _.isFunction(options.retryStrategy) ? options.retryStrategy : RetryStrategies.HTTPOrNetworkError;

/**
* Return a number representing how long request-retry should wait before trying again the request
* @type {Boolean} (err, response, body) -> Number
*/
this.delayStrategy = _.isFunction(options.delayStrategy) ? options.delayStrategy : function() { return this.retryDelay; };

this._timeout = null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"main": "index.js",
"scripts": {
"test": "mocha -t 1000 -R spec $(find test -name '*.test.js')",
"test": "mocha -t 2000 -R spec $(find test -name '*.test.js')",
"test-watch": "mocha -t 100000 -R min -w $(find test -name '*.test.js')",
"test-coverage": "nyc --all --statements=100 --lines=100 --functions=100 --branches=100 --check-coverage --reporter=lcov --reporter=cobertura --report-dir=coverage -- mocha -R spec -t 100000 $(find test -name '*.test.js')",
"send-coverage": "cat ./coverage/lcov.info | coveralls",
Expand Down

0 comments on commit be1fdc3

Please sign in to comment.