From 24e85f535a7fd14796eae6c9f9286751c5ac1b31 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Wed, 13 Dec 2023 19:48:30 +0100 Subject: [PATCH] "Gracefully" exit when receiving sigint --- Dockerfile | 1 + src/index.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9ef0693..32d0e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,3 +17,4 @@ RUN npx tsc # Run the app CMD ["node", "dist/src/index.js"] +STOPSIGNAL SIGINT diff --git a/src/index.ts b/src/index.ts index 27e5c45..e0506ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,4 +63,17 @@ discord.on("messageCreate", message => { return queueRequest(message); }); -if (require.main === module) void discord.login(config.tokens.Discord); +if (require.main === module) { + void discord.login(config.tokens.Discord); + process.on("SIGINT", () => { + console.log("got SIGINT, exiting"); + //FIXME: finish executing requests then exit + discord.destroy() + .then(() => process.exit()) + .catch((e) => { + console.error("Failed to gracefully exit"); + console.error(e); + process.exit(); + }); + }); +}