Added isShuttigDown var to handle case of multiple kill/interupt signals

This commit is contained in:
Alex Holliday committed 2024-10-31 15:59:51 +08:00
1 parent 5a5c0c610d
commit 0f30d58125
1 file changed
+6 -1
+6 -1
View File
@@ -45,6 +45,7 @@ import NotificationService from "./service/notificationService.js";
import db from "./db/mongo/MongoDB.js";
const SERVICE_NAME = "Server";
let isShuttingDown = false;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -141,6 +142,10 @@ const startApp = async () => {
);
const shutdown = async () => {
if (isShuttingDown) {
return;
}
isShuttingDown = true;
logger.info({ message: "Attempting graceful shutdown" });
setTimeout(() => {
logger.error({
@@ -149,7 +154,7 @@ const startApp = async () => {
method: "shutdown",
});
process.exit(1);
}, 10000);
}, 2000);
try {
server.close();
await jobQueue.obliterate();