Skip to content

Instantly share code, notes, and snippets.

@talkol
Last active October 22, 2016 11:13
Show Gist options
  • Select an option

  • Save talkol/e3d694839c0471742275cd97965add13 to your computer and use it in GitHub Desktop.

Select an option

Save talkol/e3d694839c0471742275cd97965add13 to your computer and use it in GitHub Desktop.
import request from 'request';
import asyncLib from 'async';
export function pingServers(servers, onComplete) {
let failedServers = {};
asyncLib.eachSeries(servers, (url, onNextUrl) => {
let failures = 0;
asyncLib.timesSeries(3, (n, onNextAttempt) => {
request(url, (error, response) => {
if (error || response.statusCode !== 200) failures++;
setTimeout(onNextAttempt, 10000);
});
}, () => {
if (failures > 0) failedServers[url] = failures;
onNextUrl();
});
}, () => {
onComplete(failedServers);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment