diff --git a/lib/queue/worker.js b/lib/queue/worker.js index 2213dfcf..c5f8fdfa 100644 --- a/lib/queue/worker.js +++ b/lib/queue/worker.js @@ -43,6 +43,8 @@ function Worker( queue, type ) { this.client = Worker.client || (Worker.client = redis.createClient()); this.running = true; this.job = null; + this.postpone = (queue && queue._options && queue._options.postponeWorker && typeof queue._options.postponeWorker === 'function') ? + queue._options.postponeWorker : function() { return 0 }; } /** @@ -268,6 +270,10 @@ Worker.prototype.getJob = function( fn ) { if( !self.running ) { return fn('Already Shutdown'); } + var postponeTimeoutMs = self.postpone(self.type); + if ( postponeTimeoutMs > 0 ) { + return setTimeout(fn, postponeTimeoutMs); + } // alloc a client for this job type var client = clients[ self.type ] || (clients[ self.type ] = redis.createClient()); // BLPOP indicates we have a new inactive job to process