Permalink
Browse files

Merge pull request #126 from mathrawka/master

Delay a failed job that was delayed
  • Loading branch information...
2 parents cac8132 + f3c8cb7 commit 4c284cec91d1ec7940e0dd71874a79dc9a27292c @tj tj committed Sep 25, 2012
Showing with 13 additions and 8 deletions.
  1. +1 −2 lib/queue/job.js
  2. +11 −5 lib/queue/worker.js
  3. +1 −1 package.json
View
@@ -335,8 +335,7 @@ Job.prototype.progress = function(complete, total){
Job.prototype.delay = function(ms){
if (0 == arguments.length) return this._delay;
this._delay = ms;
- this._state = 'delayed';
- return this;
+ return this.state('delayed');
};
/**
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);
});
};
View
@@ -1,6 +1,6 @@
{
"name": "kue"
- , "version": "0.4.0"
+ , "version": "0.4.1"
, "description": "Feature rich priority job queue backed by redis"
, "keywords": ["job", "queue", "worker", "redis"]
, "author": "TJ Holowaychuk <tj@learnboost.com>"

0 comments on commit 4c284ce

Please sign in to comment.