Skip to content

Commit

Permalink
Merge pull request #188 from ijayasin/master
Browse files Browse the repository at this point in the history
Update `updated_at` timestamp during `log`, `progress`, `attempt`, or `state` changes.
  • Loading branch information
drudge committed Mar 19, 2013
2 parents 6db47cd + 785e80a commit 287477f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/queue/job.js
Expand Up @@ -288,6 +288,7 @@ Job.prototype.log = function(str){
}); });


this.client.rpush('q:job:' + this.id + ':log', str); this.client.rpush('q:job:' + this.id + ':log', str);
this.set('updated_at', Date.now());
return this; return this;
}; };


Expand Down Expand Up @@ -334,6 +335,7 @@ Job.prototype.progress = function(complete, total){
if (0 == arguments.length) return this._progress; if (0 == arguments.length) return this._progress;
var n = Math.min(100, complete / total * 100 | 0); var n = Math.min(100, complete / total * 100 | 0);
this.set('progress', n); this.set('progress', n);
this.set('updated_at', Date.now());
events.emit(this.id, 'progress', n); events.emit(this.id, 'progress', n);
return this; return this;
}; };
Expand Down Expand Up @@ -388,6 +390,7 @@ Job.prototype.attempt = function(fn){
client.hsetnx(key, 'max_attempts', 1, function(){ client.hsetnx(key, 'max_attempts', 1, function(){
client.hget(key, 'max_attempts', function(err, max){ client.hget(key, 'max_attempts', function(err, max){
client.hincrby(key, 'attempts', 1, function(err, attempts){ client.hincrby(key, 'attempts', 1, function(err, attempts){
self.set('updated_at', Date.now());
fn(err, Math.max(0, max - attempts), attempts, max); fn(err, Math.max(0, max - attempts), attempts, max);
}); });
}); });
Expand Down Expand Up @@ -460,6 +463,7 @@ Job.prototype.state = function(state){
client.zadd('q:jobs:' + this.type + ':' + state, this._priority, this.id); client.zadd('q:jobs:' + this.type + ':' + state, this._priority, this.id);
// increase available jobs, used by Worker#getJob() // increase available jobs, used by Worker#getJob()
if ('inactive' == state) client.lpush('q:' + this.type + ':jobs', 1); if ('inactive' == state) client.lpush('q:' + this.type + ':jobs', 1);
this.set('updated_at', Date.now());
return this; return this;
}; };


Expand Down

0 comments on commit 287477f

Please sign in to comment.