Skip to content

Commit

Permalink
fix(worker): better disconnect when blocking connection
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Jun 16, 2022
1 parent 478ed16 commit b9ea7f4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/queue.js
Expand Up @@ -570,7 +570,11 @@ async function redisClientDisconnect(client) {
}

Queue.prototype.disconnect = async function() {
await Promise.all(this.clients.map(redisClientDisconnect));
await Promise.all(
this.clients.map(client =>
client.blocked ? client.disconnect() : redisClientDisconnect(client)
)
);
};

Queue.prototype.removeJobs = function(pattern) {
Expand Down Expand Up @@ -1190,11 +1194,13 @@ Queue.prototype.getNextJob = async function() {
// Waiting for new jobs to arrive
//
try {
this.bclient.blocked = true;
const jobId = await this.bclient.brpoplpush(
this.keys.wait,
this.keys.active,
this.settings.drainDelay
);
this.bclient.blocked = false;

if (jobId) {
return this.moveToActive(jobId);
Expand Down

0 comments on commit b9ea7f4

Please sign in to comment.