Skip to content

Instantly share code, notes, and snippets.

@keeth
Last active Aug 4, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@keeth 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