Skip to content

Commit

Permalink
fix(pause): don't initialize bclient if not waiting for jobs to finish
Browse files Browse the repository at this point in the history
This is the same change as OptimalBits#1347 but for `pause(true, true)`.
  • Loading branch information
gabegorelick committed Nov 8, 2019
1 parent 8c06c5f commit 39bb48c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/queue.js
Expand Up @@ -779,6 +779,11 @@ Queue.prototype.pause = function(isLocal, doNotWaitActive) {
});
}

if (!this.bclientInitialized) {
// bclient not yet initialized, so no jobs to wait for
return;
}

if (doNotWaitActive) {
// Force reconnection of blocking connection to abort blocking redis call immediately.
return redisClientDisconnect(this.bclient).then(() => {
Expand Down
11 changes: 11 additions & 0 deletions test/test_pause.js
Expand Up @@ -399,6 +399,17 @@ describe('.pause', () => {
'getNextJob should return without getting job'
);
});

it('should not initialize blocking client if not already initialized', async () => {
const createClient = sinon.spy(() => client);
const queue = utils.buildQueue('pause-queue', { createClient });

await queue.pause(true, true);
const bClientCalls = createClient
.getCalls()
.filter(c => c.args[0] === 'bclient');
expect(bClientCalls).to.have.lengthOf(0);
});
});
});
});

0 comments on commit 39bb48c

Please sign in to comment.