Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import _ from 'lodash';
  2. import fetch from 'node-fetch';
  3. import delay from 'delay';
  4. import co from 'co';
  5.  
  6. export const pingServers = (servers) => co(function*() {
  7. let failedServers = {};
  8. for (const url of servers) {
  9. let failures = 0;
  10. for (const i of _.range(3)) {
  11. const response = yield fetch(url);
  12. if (!response.ok) failures++;
  13. yield delay(10000);
  14. }
  15. if (failures > 0) failedServers[url] = failures;
  16. }
  17. return failedServers;
  18. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement