"Gracefully" exit when receiving sigint

This commit is contained in:
Wroclaw 2023-12-13 19:48:30 +01:00
parent 02a5b0f7b9
commit 24e85f535a
2 changed files with 15 additions and 1 deletions

View file

@ -17,3 +17,4 @@ RUN npx tsc
# Run the app # Run the app
CMD ["node", "dist/src/index.js"] CMD ["node", "dist/src/index.js"]
STOPSIGNAL SIGINT

View file

@ -63,4 +63,17 @@ discord.on("messageCreate", message => {
return queueRequest(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();
});
});
}