mirror of
https://github.com/dotFionn/iassure-wx.git
synced 2026-03-21 06:22:56 -05:00
Add interrupt signal handling for graceful server shutdown
This commit is contained in:
@@ -28,8 +28,24 @@ app.use((err, req: Request, res: Response, next: NextFunction) => {
|
|||||||
nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData)
|
nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData)
|
||||||
wxService.wrappedGenerateData();
|
wxService.wrappedGenerateData();
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
const server = app.listen(PORT, () => {
|
||||||
console.log(
|
console.log(
|
||||||
`application is listening on port ${PORT}`,
|
`application is listening on port ${PORT}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const shutdown = (signal: string) => {
|
||||||
|
console.log(`${signal} signal received. Shutting down.`);
|
||||||
|
server.close((err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(`Failed to shut down server gracefully: ${err}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Server closed');
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||||
|
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||||
|
|||||||
Reference in New Issue
Block a user