diff --git a/lib/queue.js b/lib/queue.js index d568a4d60..c28b4568b 100755 --- a/lib/queue.js +++ b/lib/queue.js @@ -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 = @@ -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.