Skip to content

Instantly share code, notes, and snippets.

@talkol
Created October 22, 2016 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkol/c2d67646b0f594bf46ee0f138c2d1b56 to your computer and use it in GitHub Desktop.
Save talkol/c2d67646b0f594bf46ee0f138c2d1b56 to your computer and use it in GitHub Desktop.
import _ from 'lodash';
import fetch from 'node-fetch';
import delay from 'delay';
export function pingServers(servers) {
return _.reduce(servers, (failedServersAccumulator, url) => {
return failedServersAccumulator.then((failedServers) => {
return _.reduce(_.range(3), (failuresAccumulator) => {
return failuresAccumulator.then(delay(10000)).then((failures) => {
return fetch(url).then((response) => {
return response.ok ? failures : failures + 1;
});
});
}, Promise.resolve(0)).then((failures) => {
if (failures > 0) failedServers[url] = failures;
return failedServers;
});
});
}, Promise.resolve({}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment