feat: handle termination

This commit is contained in:
2019-01-30 09:51:31 -07:00
parent ed6186f63b
commit 7bbe31f4ea

View File

@@ -42,6 +42,15 @@ async function run() {
// initial kickoff // initial kickoff
await fetchAndIndex().catch(handleError); await fetchAndIndex().catch(handleError);
// listen for termination
const terminate = type => () => {
console.log(`Terminating [${type}]`);
process.exit(0);
};
process.on('SIGINT', terminate('SIGINT'));
process.on('SIGTERM', terminate('SIGTERM'));
process.on('SIGKILL', terminate('SIGKILL'));
// scheduled running // scheduled running
if (interval === 0) return; if (interval === 0) return;
logger.debug(`Starting interval (${interval}s)...`); logger.debug(`Starting interval (${interval}s)...`);