Compare commits

...

1 Commits

Author SHA1 Message Date
Flea Flicker 8e8f65f328 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>
2026-04-15 01:46:28 +00:00
+16 -1
View File
@@ -187,9 +187,24 @@ api.route("/search", searchRouter);
const port = Number(process.env.PORT ?? 3000);
await initAuth();
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)
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;