BullMQ
Search…
Failing fast when Redis is down
By design, BullMQ will reconnect automatically and if you add new jobs to a queue while the queue instance is disconnected from Redis, the add command will not fail, instead the call will keep waiting for a reconnection to occur until it can complete.
This behavior is not always desirable; for example, if you have implemented a REST API that results in a call to "add", you do not want to keep the HTTP call busy while the "add" is waiting for the queue to reconnect to Redis. In this case, you can just pass the option "enableOfflineQueue: false", so that "ioredis" do not queue the commands and instead throws an exception:
1
const myQueue = new Queue("transcoding", {
2
connection: {
3
enableOfflineQueue: false,
4
},
5
});
6
7
app.post("/jobs", async (req, res) => {
8
try {
9
const job = await myQueue.add("myjob", { req.body });
10
res.status(201).json(job.id);
11
}catch(err){
12
res.status(503).send(err);
13
}
14
})
Copied!
In this way, the caller can catch this temporal error and act upon it, maybe doing some retries or giving up depending on its requirements.
Currently, there is a limitation in that the Redis instance must at least be online while the queue is being instantiated.
Copy link