From fe884999f4932c4e350f4905c724870e2965b6ff Mon Sep 17 00:00:00 2001 From: canove Date: Sat, 7 Nov 2020 17:30:42 -0300 Subject: [PATCH] chore: add graceful shutdown --- backend/src/libs/socket.ts | 4 +++- backend/src/server.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/libs/socket.ts b/backend/src/libs/socket.ts index c9cb942..621d927 100644 --- a/backend/src/libs/socket.ts +++ b/backend/src/libs/socket.ts @@ -7,7 +7,8 @@ let io: SocketIO; export const initIO = (httpServer: Server): SocketIO => { io = socketIo(httpServer); - if (process.env.IO_REDIS_SERVER) { + + if (process.env.NODE_ENV === "PRODUCTION") { io.adapter( socketRedis({ host: process.env.IO_REDIS_SERVER, @@ -15,6 +16,7 @@ export const initIO = (httpServer: Server): SocketIO => { }) ); } + io.on("connection", socket => { console.log("Client Connected"); socket.on("joinChatBox", ticketId => { diff --git a/backend/src/server.ts b/backend/src/server.ts index 00d12ac..2fffb62 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -1,3 +1,4 @@ +import gracefulShutdown from "http-graceful-shutdown"; import app from "./app"; import { initIO } from "./libs/socket"; import { StartAllWhatsAppsSessions } from "./services/WbotServices/StartAllWhatsAppsSessions"; @@ -8,3 +9,4 @@ const server = app.listen(process.env.PORT, () => { initIO(server); StartAllWhatsAppsSessions(); +gracefulShutdown(server);