Skip to content

Commit 30e4a3d

Browse files
committed
Updated getConcurrentJobs() param to be queueLifespanRemaining instead of queueLifespan, which is how param will actually be used. Also updated test with updated term.
1 parent d473af9 commit 30e4a3d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Models/Queue.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ export class Queue {
207207
* worker function that has concurrency X > 1, then X related (jobs with same name)
208208
* jobs will be returned.
209209
*
210-
* If queue is running with a lifespan, only jobs with timeouts at least 500ms < than lifespan
210+
* If queue is running with a lifespan, only jobs with timeouts at least 500ms < than REMAINING lifespan
211211
* AND a set timeout (ie timeout > 0) will be returned. See Queue.start() for more info.
212212
*
213-
* @param queueLifespan {number} - The lifespan of the current queue process (defaults to indefinite lifespan).
213+
* @param queueLifespanRemaining {number} - The remaining lifespan of the current queue process (defaults to indefinite).
214214
* @return {promise} - Promise resolves to an array of job(s) to be processed next by the queue.
215215
*/
216-
async getConcurrentJobs(queueLifespan = 0) {
216+
async getConcurrentJobs(queueLifespanRemaining = 0) {
217217

218218
let concurrentJobs = [];
219219

@@ -224,9 +224,9 @@ export class Queue {
224224

225225
// Build query string
226226
// If queueLife
227-
const timeoutUpperBound = (queueLifespan - 500 > 0) ? queueLifespan - 499 : 0; // Only get jobs with timeout at least 500ms < queueLifespan.
227+
const timeoutUpperBound = (queueLifespanRemaining - 500 > 0) ? queueLifespanRemaining - 499 : 0; // Only get jobs with timeout at least 500ms < queueLifespanRemaining.
228228

229-
const initialQuery = (queueLifespan)
229+
const initialQuery = (queueLifespanRemaining)
230230
? 'active == FALSE AND failed == null AND timeout > 0 AND timeout < ' + timeoutUpperBound
231231
: 'active == FALSE AND failed == null';
232232

@@ -243,7 +243,7 @@ export class Queue {
243243

244244
const concurrency = this.worker.getConcurrency(nextJob.name);
245245

246-
const allRelatedJobsQuery = (queueLifespan)
246+
const allRelatedJobsQuery = (queueLifespanRemaining)
247247
? 'name == "'+ nextJob.name +'" AND active == FALSE AND failed == null AND timeout > 0 AND timeout < ' + timeoutUpperBound
248248
: 'name == "'+ nextJob.name +'" AND active == FALSE AND failed == null';
249249

tests/Queue.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe('Models/Queue', function() {
286286

287287
});
288288

289-
it('#getConcurrentJobs(queueLifespan) should work as expected for queues started with a lifespan.', async () => {
289+
it('#getConcurrentJobs(queueLifespanRemaining) should work as expected for queues started with a lifespan.', async () => {
290290

291291
const queue = await QueueFactory();
292292
const jobName = 'job-name';
@@ -295,7 +295,7 @@ describe('Models/Queue', function() {
295295
concurrency: 3
296296
});
297297

298-
// Test that jobs with no timeout set will not be returned by getConcurrentJobs() if queueLifespan is passed.
298+
// Test that jobs with no timeout set will not be returned by getConcurrentJobs() if queueLifespanRemaining is passed.
299299
queue.createJob(jobName, {}, {
300300
timeout: 0
301301
}, false);
@@ -314,7 +314,7 @@ describe('Models/Queue', function() {
314314
// Reset DB
315315
queue.flushQueue();
316316

317-
// Test that jobs with timeout not at least 500ms less than queueLifespan are not grabbed.
317+
// Test that jobs with timeout not at least 500ms less than queueLifespanRemaining are not grabbed.
318318
queue.createJob(jobName, {}, {
319319
timeout: 500
320320
}, false);

0 commit comments

Comments
 (0)