Best way to handle a bad connection? #372
Replies: 1 comment 2 replies
-
Hello! I wanted to revive this discussion, as I had a similar question regarding bad connections, and what the best practice should be. PrereqsI have ScenarioI have the following running:
On the Worker service I am following the advice for gracefully shutting down workers: const gracefulShutdown = async (signal: string) => {
console.log(`Received ${signal}, closing server...`);
try {
console.log("Gracefully closing worker...");
await worker.close();
console.log("Worker closed...");
} catch (error: any) {
console.error("Failed to close worker....", error.message);
process.exit(1);
}
// Other asynchronous closings
process.exit(0);
};
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
process.on("SIGTERM", () => gracefulShutdown("SIGTERM")); Situation AIf I have all services up and running, and I provide a valid Redis The results are as expected and it gracefully shuts down. Likewise, if I spin up everything, then I shut down the Redis server. The worker service will begin logging Situation BIf I have all three running, but I provide an initially invalid Redis It will try to call the Eventually in the terminal it'll just keep logging the Furthermore, if I update to a valid QuestionHow would you handle Situation B? It seems like even after trying to do |
Beta Was this translation helpful? Give feedback.
-
Hi there!
I'm trying to make sure I properly handle the case where BullMQ can't establish a connection to redis either because it's down or misconfigured. I'd ideally like to catch the error and execute some other code, not have it error on the server.
If I just try to create a queue on a bad connection like this:
const queue = new Queue(queueName, { connection });
I get this:
And it seems like
ioredis
will continuously retry from there.I looked in the source and queues appear to emit an error event when the connection fails so I updated to this:
And that gets me to:
And there are no more retries because I'm closing the queue. But is there a recommended way to catch that other error and handle it gracefully?
Beta Was this translation helpful? Give feedback.
All reactions