Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #133 #163

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/queue/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/*!
* kue - Worker
* Copyright (c) 2011 LearnBoost <[email protected]>
Expand Down Expand Up @@ -93,7 +93,7 @@ Worker.prototype.error = function(err, job){
* @api private
*/

Worker.prototype.failed = function(job, err, fn){
Worker.prototype.failed = function(job, err, fn, cont){
var self = this;
events.emit(job.id, 'failed');
job.failed().error(err);
Expand All @@ -103,7 +103,7 @@ Worker.prototype.failed = function(job, err, fn){
remaining
? job.inactive()
: job.failed();
self.start(fn);
if(cont) self.start(fn);
});
};

Expand All @@ -121,15 +121,19 @@ Worker.prototype.failed = function(job, err, fn){

Worker.prototype.process = function(job, fn){
var self = this
, start = new Date;
, start = new Date
, result;
job.active();
fn(job, function(err){
if (err) return self.failed(job, err, fn);
result = fn(job, function(err,cont){
cont = cont && result;
if (err) return self.failed(job, err, fn, cont);
job.complete();
job.set('duration', job.duration = new Date - start);
self.emit('job complete', job);
events.emit(job.id, 'complete');
self.start(fn);
process.nextTick(function(){
if(cont) self.start(fn);
});
});
return this;
};
Expand All @@ -155,7 +159,7 @@ Worker.prototype.zpop = function(key, fn){
};

/**
* Attempt to fetch the next job.
* Attempt to fetch the next job.
*
* @param {Function} fn
* @api private
Expand Down