mirror of
https://github.com/chenasraf/venom.git
synced 2026-05-17 17:28:08 +00:00
fix: better shutdown handling
This commit is contained in:
17
src/index.ts
17
src/index.ts
@@ -24,12 +24,19 @@ client.once(Events.ClientReady, (readyClient) => {
|
||||
|
||||
client.login(DISCORD_TOKEN)
|
||||
|
||||
function shutdown(signal: string) {
|
||||
return async () => {
|
||||
function terminator(signal: string) {
|
||||
process.once(signal, async (code: string | number | Error) => {
|
||||
logger.warn(`Received ${signal}, shutting down...`)
|
||||
await saveBrain()
|
||||
}
|
||||
process.exit(isNaN(+code) ? 1 : +code)
|
||||
})
|
||||
}
|
||||
|
||||
process.once('SIGINT', shutdown('SIGINT'))
|
||||
process.once('SIGTERM', shutdown('SIGTERM'))
|
||||
// prettier-ignore
|
||||
const signals = [
|
||||
'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1',
|
||||
'SIGSEGV', 'SIGUSR2', 'SIGTERM', 'beforeExit', 'exit',
|
||||
]
|
||||
for (const sig of signals) {
|
||||
terminator(sig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user