retryer v1.1.2
retryer.js
retryer.js is a tiny, battle tested library that enables you to retry promises.
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 retryerExamples & 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 Name | Type | Default | Description | Example |
|---|---|---|---|---|
total | Number | 10 | Number of attempts to retry | options-total.js |
timeout | Number | 1000 | Backoff timeout (in ms) | options-timeout.js |
onStart | Function | function(attempt) {..} | Is triggered on start for each attempt | options-on-start.js |
onError | Function | function(error, attempt) {..} | Is triggered on error for each attempt | options-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.
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago