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"; import db from "./db/mongo/MongoDB.js";
const SERVICE_NAME = "Server"; const SERVICE_NAME = "Server";
let isShuttingDown = false;
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
@@ -141,6 +142,10 @@ const startApp = async () => {
); );
const shutdown = async () => { const shutdown = async () => {
if (isShuttingDown) {
return;
}
isShuttingDown = true;
logger.info({ message: "Attempting graceful shutdown" }); logger.info({ message: "Attempting graceful shutdown" });
setTimeout(() => { setTimeout(() => {
logger.error({ logger.error({
@@ -149,7 +154,7 @@ const startApp = async () => {
method: "shutdown", method: "shutdown",
}); });
process.exit(1); process.exit(1);
}, 10000); }, 2000);
try { try {
server.close(); server.close();
await jobQueue.obliterate(); await jobQueue.obliterate();