Created
February 5, 2017 06:59
-
-
Save ahawkins/fbe525b3eecf4bc312cf2afc23527792 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let redis = require('redis'); | |
let retry = require('retry') | |
function ping(callback) { | |
let operation = retry.operation({ | |
retries: process.env.ATTEMPTS ? parseInt(process.env.ATTEMPTS) : 60, | |
factor: 1, | |
randomize: false | |
}); | |
operation.attempt(function(currentAttempt) { | |
try { | |
var client = redis.createClient({ | |
url: process.env.REDIS_URL | |
}); | |
client.ping(function(err, result) { | |
if(operation.retry(err)) { | |
return; | |
} | |
callback(err ? operation.mainError() : null, result); | |
}); | |
} catch(err) { | |
if(operation.retry(err)) { | |
return; | |
} | |
callback(err || operation.mainError()); | |
} | |
}); | |
}; | |
ping(function(err, result) { | |
if(err) { | |
console.log(err); | |
console.log('Connection failed'); | |
process.exit(1); | |
} else { | |
console.log('Connection ok'); | |
process.exit(0); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a guess at how it might work after skimming https://github.com/tim-kos/node-retry
i don't really understand the intended api usage of the retry module tho.