Handle SIGTERM and SIGINT signal #3

Merged
nabarun merged 1 commits from pj-stop-server into main 2025-12-09 05:33:32 +00:00
2 changed files with 18 additions and 2 deletions

View File

@ -19,9 +19,25 @@ async function startServer() {
const PORT = process.env.PORT || 6000;
app.listen(PORT, () => {
const httpServer = app.listen(PORT, () => {
console.log(`🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`);
});
const shutdown = async (signal: string) => {
console.log(`${signal} received, shutting down gracefully...`);
httpServer.close(() => {
console.log('HTTP server closed');
});
await server.stop();
console.log('Apollo server stopped');
process.exit(0);
};
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));
}
startServer().catch(error => {

View File

@ -7,7 +7,7 @@ services:
VERIFIED_PARTICIPANTS_PATH: /tmp/watcher-data/verified-participants.json
GENERATED_WATCHER_EVENTS_OUTPUT_PATH: /tmp/watcher-data/generated
working_dir: /app/
command: "node --enable-source-maps dist/index.js"
command: ["node", "--enable-source-maps", "dist/index.js"]
volumes:
- watcher-data:/tmp/watcher-data
ports: