Skip to content

Commit

Permalink
add promotion:start and promotion:end events Automattic#574
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Carrera committed Apr 15, 2015
1 parent 1b052eb commit 6db5386
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/kue.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,23 @@ Queue.prototype._promote = function( promotionOptions ) {
}
if (typeof unlock === 'function') {
// If the lock is set successfully by this process, an unlock function is passed to our callback.
self.emit('promotion:start');
client.zrangebyscore(client.getKey('jobs:delayed'), 0, Date.now(), "LIMIT", 0, limit, function (err, ids) {
if (err || !ids.length) return unlock();
if (err || !ids.length) {
self.emit('promotion:end');
return unlock();
}
totalJobs = ids.length;
jobsPromoted = 0;
ids.forEach( function(id){
Job.get(id, function(err, job) {
if (err) return;
events.emit(id, 'promotion');
job.inactive();
jobsPromoted++;
if (jobsPromoted === totalJobs) {
self.emit('promotion:end');
}
});
});
unlock();
Expand Down

0 comments on commit 6db5386

Please sign in to comment.