Last active
August 4, 2016 23:43
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it expects to be run like
node heartbeat.js myscript arg1 arg2
(it expects to find the program to run at
argv[2]
)