feat: Implement graceful server shutdown with signal handling and interval clearing.
All checks were successful
Build and Deploy / build (push) Successful in 1m16s
All checks were successful
Build and Deploy / build (push) Successful in 1m16s
This commit is contained in:
@@ -155,7 +155,7 @@ app.post('/api/packs/generate', async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
// Global Draft Timer Loop
|
||||
setInterval(() => {
|
||||
const draftInterval = setInterval(() => {
|
||||
const updates = draftManager.checkTimers();
|
||||
updates.forEach(({ roomId, draft }) => {
|
||||
io.to(roomId).emit('draft_update', draft);
|
||||
@@ -525,3 +525,25 @@ httpServer.listen(Number(PORT), '0.0.0.0', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const gracefulShutdown = () => {
|
||||
console.log('Received kill signal, shutting down gracefully');
|
||||
clearInterval(draftInterval);
|
||||
|
||||
io.close(() => {
|
||||
console.log('Socket.io closed');
|
||||
});
|
||||
|
||||
httpServer.close(() => {
|
||||
console.log('Closed out remaining connections');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
console.error('Could not close connections in time, forcefully shutting down');
|
||||
process.exit(1);
|
||||
}, 10000);
|
||||
};
|
||||
|
||||
process.on('SIGTERM', gracefulShutdown);
|
||||
process.on('SIGINT', gracefulShutdown);
|
||||
|
||||
Reference in New Issue
Block a user