feat(api): graceful shutdown for less 502 errors

This commit is contained in:
Gergő Móricz 2024-11-12 18:10:24 +01:00
parent c327d688a6
commit 740a429790

View File

@ -80,6 +80,17 @@ function startServer(port = DEFAULT_PORT) {
`For the Queue UI, open: http://${HOST}:${port}/admin/${process.env.BULL_AUTH_KEY}/queues` `For the Queue UI, open: http://${HOST}:${port}/admin/${process.env.BULL_AUTH_KEY}/queues`
); );
}); });
const exitHandler = () => {
logger.info('SIGTERM signal received: closing HTTP server')
server.close(() => {
logger.info("Server closed.");
process.exit(0);
});
};
process.on('SIGTERM', exitHandler);
process.on('SIGINT', exitHandler);
return server; return server;
} }