Skip to content

Instantly share code, notes, and snippets.

@bryanjknight
Created March 24, 2018 17:53
Show Gist options
  • Save bryanjknight/9339852313d36a761d743c3b26c5ec8b to your computer and use it in GitHub Desktop.
Save bryanjknight/9339852313d36a761d743c3b26c5ec8b to your computer and use it in GitHub Desktop.
bluebird-retry and request
'use strict';
const Promise = require('bluebird');
const PromiseRetry = require('bluebird-retry');
const request = require('request');
const retryConfig = {
timeout: 20000, // 20 seconds
interval: 2000, // retry every 10 seconds
max_tries: 10 // 10 retries
}
new PromiseRetry(function() {
return new Promise(function(resolve, reject) {
request.get('http://localhost:18630', function(err, response, body) {
if(err) {
reject(err);
}
if(!err) {
resolve("success");
}
});
});
}, retryConfig)
.then(function(result) {
console.log("Result: " + result);
}
).catch(function(err) {
console.error("Error: " + err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment