New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: cleanup whenCurrentJobsFinished #1542
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1174,49 +1174,20 @@ Queue.prototype.clean = function(grace, type, limit) { | |
* @returns {Promise} | ||
*/ | ||
Queue.prototype.whenCurrentJobsFinished = function() { | ||
return new Promise((resolve, reject) => { | ||
if (!this.bclientInitialized) { | ||
// bclient not yet initialized, so no jobs to wait for | ||
return resolve(); | ||
} | ||
|
||
// | ||
// Force reconnection of blocking connection to abort blocking redis call immediately. | ||
// | ||
const forcedReconnection = redisClientDisconnect(this.bclient).then(() => { | ||
return this.bclient.connect(); | ||
}); | ||
if (!this.bclientInitialized) { | ||
// bclient not yet initialized, so no jobs to wait for | ||
return Promise.resolve(); | ||
} | ||
|
||
Promise.all(this.processing) | ||
.then(() => { | ||
return forcedReconnection; | ||
}) | ||
.then(resolve, reject); | ||
|
||
/* | ||
this.bclient.disconnect(); | ||
this.bclient.once('end', function(){ | ||
console.error('ENDED!'); | ||
setTimeout(function(){ | ||
this.bclient.connect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed all this commented code. |
||
}, 0); | ||
}); | ||
// | ||
// Force reconnection of blocking connection to abort blocking redis call immediately. | ||
// | ||
const forcedReconnection = redisClientDisconnect(this.bclient).then(() => { | ||
return this.bclient.connect(); | ||
}); | ||
|
||
/* | ||
var stream = this.bclient.connector.stream; | ||
if(stream){ | ||
stream.on('finish', function(){ | ||
console.error('FINISHED!'); | ||
this.bclient.connect(); | ||
}); | ||
stream.on('error', function(err){ | ||
console.error('errir', err); | ||
this.bclient.connect(); | ||
}); | ||
this.bclient.connect(); | ||
} | ||
*/ | ||
//this.bclient.connect(); | ||
return Promise.all([this.processing[0]]).then(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After upgrade to latest version of bull we are seeing that on shutdown, it doesn't properly wait for all jobs to complete. It seems to me that this is likely the change that caused the problem. Was it intentional to change this to only wait for the first job? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that seems like a dumb mistake on my part. Thanks for catching it @holm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix: #1586 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the quick fix! |
||
return forcedReconnection; | ||
}); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const redis = require('ioredis'); | ||
const utils = require('./utils'); | ||
const delay = require('delay'); | ||
const sinon = require('sinon'); | ||
|
||
describe('.whenCurrentJobsFinished', () => { | ||
let client; | ||
beforeEach(() => { | ||
client = new redis(); | ||
return client.flushdb(); | ||
}); | ||
|
||
afterEach(async () => { | ||
sinon.restore(); | ||
await utils.cleanupQueues(); | ||
await client.flushdb(); | ||
return client.quit(); | ||
}); | ||
|
||
it('should handle queue with no processor', async () => { | ||
const queue = await utils.newQueue(); | ||
expect(await queue.whenCurrentJobsFinished()).to.equal(undefined); | ||
}); | ||
|
||
it('should handle queue with no jobs', async () => { | ||
const queue = await utils.newQueue(); | ||
queue.process(() => Promise.resolve()); | ||
expect(await queue.whenCurrentJobsFinished()).to.equal(undefined); | ||
}); | ||
|
||
it('should wait for job to complete', async () => { | ||
const queue = await utils.newQueue(); | ||
await queue.add({}); | ||
|
||
let finishJob; | ||
|
||
// wait for job to be active | ||
await new Promise(resolve => { | ||
queue.process(() => { | ||
resolve(); | ||
|
||
return new Promise(resolve => { | ||
finishJob = resolve; | ||
}); | ||
}); | ||
}); | ||
|
||
let isFulfilled = false; | ||
const finished = queue.whenCurrentJobsFinished().then(() => { | ||
isFulfilled = true; | ||
}); | ||
|
||
await delay(100); | ||
expect(isFulfilled).to.equal(false); | ||
|
||
finishJob(); | ||
expect(await finished).to.equal( | ||
undefined, | ||
'whenCurrentJobsFinished should resolve once jobs are finished' | ||
); | ||
}); | ||
|
||
it('should wait for job to fail', async () => { | ||
const queue = await utils.newQueue(); | ||
await queue.add({}); | ||
|
||
let rejectJob; | ||
|
||
// wait for job to be active | ||
await new Promise(resolve => { | ||
queue.process(() => { | ||
resolve(); | ||
|
||
return new Promise((resolve, reject) => { | ||
rejectJob = reject; | ||
}); | ||
}); | ||
}); | ||
|
||
let isFulfilled = false; | ||
const finished = queue.whenCurrentJobsFinished().then(() => { | ||
isFulfilled = true; | ||
}); | ||
|
||
await delay(100); | ||
expect(isFulfilled).to.equal(false); | ||
|
||
rejectJob(); | ||
expect(await finished).to.equal( | ||
undefined, | ||
'whenCurrentJobsFinished should resolve once jobs are finished' | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the unnecessary
new Promise
.