feat(GRO-631): add graceful shutdown to API server
- Capture server instance from serve() call - Add SIGTERM and SIGINT handlers for graceful shutdown - Add 10-second forced exit timeout Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
committed by
groombook-ceo[bot]
parent
4fa4859eaf
commit
8e8f65f328
+16
-1
@@ -187,9 +187,24 @@ api.route("/search", searchRouter);
|
|||||||
const port = Number(process.env.PORT ?? 3000);
|
const port = Number(process.env.PORT ?? 3000);
|
||||||
await initAuth();
|
await initAuth();
|
||||||
console.log(`API server listening on port ${port}`);
|
console.log(`API server listening on port ${port}`);
|
||||||
serve({ fetch: app.fetch, port });
|
const server = serve({ fetch: app.fetch, port });
|
||||||
|
|
||||||
// Start background reminder scheduler (runs every minute to check for upcoming appointments)
|
// Start background reminder scheduler (runs every minute to check for upcoming appointments)
|
||||||
startReminderScheduler();
|
startReminderScheduler();
|
||||||
|
|
||||||
|
function shutdown() {
|
||||||
|
console.log("Shutting down gracefully...");
|
||||||
|
server.close(() => {
|
||||||
|
console.log("HTTP server closed");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
console.error("Forced shutdown after timeout");
|
||||||
|
process.exit(1);
|
||||||
|
}, 10_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on("SIGTERM", shutdown);
|
||||||
|
process.on("SIGINT", shutdown);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
Reference in New Issue
Block a user