Permalink
Browse files

If a job with a delay has more attempts, honor the original delay

  • Loading branch information...
1 parent cac8132 commit c75b0441cb5a588ea3ad61f11c4b4108445c95cc @emostar emostar committed Aug 19, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/queue/worker.js
View
@@ -85,8 +85,8 @@ Worker.prototype.error = function(err, job){
/**
* Process a failed `job`. Set's the job's state
* to "failed" unless more attempts remain, in which
- * case the job is marked as "inactive" and remains
- * in the queue.
+ * case the job is marked as "inactive" or "delayed"
+ * and remains in the queue.
*
* @param {Function} fn
* @return {Worker} for chaining
@@ -100,9 +100,15 @@ Worker.prototype.failed = function(job, err, fn){
self.error(err, job);
job.attempt(function(error, remaining, attempts, max){
if (error) return self.error(error, job);
- remaining
- ? job.inactive()
- : job.failed();
+ if (remaining) {
+ if (job.delay()) {
+ job.delay(job.delay());
+ } else {
+ job.inactive();
+ }
+ } else {
+ job.failed();
+ }
self.start(fn);
});
};

0 comments on commit c75b044

Please sign in to comment.