Skip to content

Instantly share code, notes, and snippets.

@keeth
Last active August 4, 2016 23:43
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 keeth/c02f54dacddd42660f9f09a7acb15118 to your computer and use it in GitHub Desktop.
Save keeth/c02f54dacddd42660f9f09a7acb15118 to your computer and use it in GitHub Desktop.
a better travis_wait (it prints the script output as it comes in, rather than all at the end)
const spawn = require('child_process').spawn;
const command = process.argv[2];
const args = process.argv.slice(3);
const child = spawn(command, args);
console.log(`heartbeat: running command ${command} with args ${args}`);
const heartbeat = setInterval(() => {
console.log('❤️');
}, 1000 * 60);
const timeout = setTimeout(() => {
console.log('heartbeat: child process timed out after 60 min');
clearInterval(heartbeat);
process.exit(1);
}, 1000 * 60 * 60);
child.stdout.on('data', (data) => {
console.log(data.toString().replace(/\r?\n$/, ''));
});
child.stderr.on('data', (data) => {
console.log(data.toString().replace(/\r?\n$/, ''));
});
child.on('close', (code) => {
console.log(`heartbeat: child process exited with code ${code}`);
clearInterval(heartbeat);
clearTimeout(timeout);
process.exit(code);
});
@keeth
Copy link
Author

keeth commented Aug 4, 2016

it expects to be run like node heartbeat.js myscript arg1 arg2

(it expects to find the program to run at argv[2])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment