Skip to content

Instantly share code, notes, and snippets.

@tyler-boyd
Created November 8, 2019 21:14
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 tyler-boyd/5cdc486cb1edf1df680ed2ec55368678 to your computer and use it in GitHub Desktop.
Save tyler-boyd/5cdc486cb1edf1df680ed2ec55368678 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const process = require("process");
const fetch = require("node-fetch");
if (process.argv.length < 3 || process.argv.length > 4) {
console.error(`Usage: ${process.argv[0]} endpoint timeout`);
process.exit(2);
}
const endpoint = process.argv[2];
const timeout = parseInt(process.argv[3]) || 10;
const wait = (delay) => {
return new Promise((r) => setTimeout(r, delay));
};
console.log(`Going to try hitting ${endpoint} for ${timeout} seconds`);
(async () => {
for(let tries = 0; tries < timeout; tries += 1) {
try {
await fetch(endpoint);
console.log(`${endpoint} is up after ${tries} seconds`);
process.exit(0);
} catch (err) {
if (tries % 15 === 0) {
console.log(`${endpoint} is not up after ${tries} seconds`);
}
await wait(1000);
}
}
console.error(`${endpoint} never came up 😭`);
process.exit(1);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment