From 559c7d64d6aafd34bdc64d0a4c526313e7203c89 Mon Sep 17 00:00:00 2001 From: joe fleming Date: Wed, 30 Jan 2019 09:51:31 -0700 Subject: [PATCH] feat: handle termination --- bin/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/index.js b/bin/index.js index ef3b6ba..41e3a0a 100644 --- a/bin/index.js +++ b/bin/index.js @@ -42,6 +42,14 @@ async function run() { // initial kickoff 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')); + // scheduled running if (interval === 0) return; logger.debug(`Starting interval (${interval}s)...`);