Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-gshe committed Oct 28, 2020
1 parent f63883b commit 8e99209
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ const Queue = function Queue(name, url, opts) {
guardInterval: 5000,
retryProcessDelay: 5000,
drainDelay: 5,
backoffStrategies: {}
backoffStrategies: {},
maxWaitingLimit: Number.MAX_VALUE
});

this.settings.lockRenewTime =
Expand Down Expand Up @@ -907,14 +908,22 @@ Queue.prototype.updateDelayTimer = function() {
]);

// Schedule next processing of the delayed jobs
if (delay <= 0) {
// Next set of jobs are due right now, process them also
this.updateDelayTimer();
} else {
// Update the delay set when the next job is due
// or the next guard time
this.delayTimer = setTimeout(() => this.updateDelayTimer(), delay);
}
this.getWaitingCount().then(cnt => {
if (cnt < this.settings.maxWaitingLimit) {
// limit the waiting queue grows too quickly
this.delayTimer = setTimeout(
() => this.updateDelayTimer(),
this.settings.guardInterval
);
} else if (delay <= 0) {
// Next set of jobs are due right now, process them also
this.updateDelayTimer();
} else {
// Update the delay set when the next job is due
// or the next guard time
this.delayTimer = setTimeout(() => this.updateDelayTimer(), delay);
}
});

// Silence warnings about promise created but not returned.
// This isn't an issue since we emit errors.
Expand Down

0 comments on commit 8e99209

Please sign in to comment.