Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

feat: avoid double SIGINT crashing

Gergo Moricz9cd7d79b643f
diff --git a/apps/api/src/services/queue-worker.ts b/apps/api/src/services/queue-worker.ts
index d68018564..90d0dac5c 100644
--- a/apps/api/src/services/queue-worker.ts
+++ b/apps/api/src/services/queue-worker.ts
@@ -103,7 +103,12 @@ wsq.process(
}
);
+let shuttingDown = false;
+
process.on("SIGINT", async () => {
+ if (shuttingDown) return;
+ shuttingDown = true;
+
console.log("Gracefully shutting down...");
await wsq.pause(true, true);
@@ -112,8 +117,6 @@ process.on("SIGINT", async () => {
const jobs = await Promise.all(myJobs.map(x => wsq.getJob(x)));
console.log("Removing", jobs.length, "jobs...");
await Promise.all(jobs.map(async x => {
- // await wsq.client.del(await x.lockKey());
- // await x.takeLock();
await x.moveToFailed({ message: "interrupted" });
await x.remove();
}));