1.1.2 • Published 7 years ago

retryer v1.1.2

Weekly downloads
11
License
ISC
Repository
github
Last release
7 years ago

retryer.js

retryer.js is a tiny, battle tested library that enables you to retry promises.

GitHub release Codacy Badge Build Status npm License

Quickstart

// STEP 1: create function that returns promise
function sendRequest() {
   return request('http://site.com/')
}

// STEP 2: Pass that function to the retry(FUNCTION_NAME)
retry(sendRequest)
  .then(data => console.log('Connected 🎉'))
  .catch(error => console.log('Not connected 🤷‍'))

Install

You can get it on npm.

npm install --save retryer

Examples & HOWTO

Take a look at our many examples:

  • basic: How to retry promise.
  • request: How to retry HTTP request.
  • mongoose: How to reconnect to Mongoose.
  • mongodb: How to reconnect to MongoDB.
  • redis: How to reconnect to Redis.
  • async/await: How to retry async/await.
  • bluebird: How to retry bluebird promise.
  • bunyan: How to integrate bunyan logger.
  • winson: How to integrate winson logger.
  • advanced-options: How to use options and customise log messages.
  • Couldn't find appropriate example? Create an issue and we will prepare one 💪

Fully customisable

Change anything you need to fit your needs.

Custom loggers

You can easely integrate any custom logger. Take a look at examples:

Available Options

Option NameTypeDefaultDescriptionExample
totalNumber10Number of attempts to retryoptions-total.js
timeoutNumber1000Backoff timeout (in ms)options-timeout.js
onStartFunctionfunction(attempt) {..}Is triggered on start for each attemptoptions-on-start.js
onErrorFunctionfunction(error, attempt) {..}Is triggered on error for each attemptoptions-on-error.js

How to Pass Options?

Pass an options as a second argument.

// Syntax
retry(fn, OPTIONS);

// Example: retry request 3 times with 2.5s timeout
// const options = {
//   timeout: 2500,
//   total: 3,
//   function(attempt) {..},
//   function(err, attempt) {..}
// };
//
// retry(sendRequest, options);

Development

Code Quality

Run npm run lint to statically validate the code.

Run npm run test to run unit tests.

Performance Tests

Run npm run perf to run the performance tests.

Need Help?

Please submit an issue on GitHub and provide information about your setup.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.33

7 years ago

0.1.32

7 years ago

0.1.30

7 years ago

0.1.29

7 years ago

0.1.23

7 years ago

0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.17

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago