From 7bbe31f4ea4b122c051b74e455bf779b8e0eada4 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/index.js b/bin/index.js index ef3b6ba..abccbb5 100644 --- a/bin/index.js +++ b/bin/index.js @@ -42,6 +42,15 @@ 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')); + process.on('SIGKILL', terminate('SIGKILL')); + // scheduled running if (interval === 0) return; logger.debug(`Starting interval (${interval}s)...`);