whenCurrentJobsFinished initializes bclient unnecessarily
Created by: gabegorelick
Description
Bull typically does a good job of lazily connecting to Redis. But the following code causes the blocking client to be initialized unnecessarily:
If bclient
hasn't been initialized yet, then we're connecting for no reason.
Minimal, Working Test code to reproduce the issue.
const Queue = require('bull');
const Redis = require('ioredis');
const queue = new Queue('foo', {
createClient (type) {
if (type === 'bclient') {
// enforce that we don't waste connections for read-only queues
throw new Error('This queue is read-only');
}
return new Redis();
}
});
queue.whenCurrentJobsFinished();
Bull version
develop
branch
Additional information
Also reproducible when calling queue.pause(true)
since that calls whenCurrentJobsFinished
internally. Workaround for that is to call queue.pause(true, true)
so that whenCurrentJobsFinished
is not called. But that only works if you're sure there are no jobs to wait for.