Skip to content

Commit

Permalink
corrected lock renew logic
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Jun 20, 2016
1 parent 70dad24 commit 8a9e455
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ Queue.prototype.processStalledJob = function(job){
if(!job){
return Promise.resolve();
}else{
scripts.getStalledJob(this, job, _this.token).then(function(isStalled){
return scripts.getStalledJob(this, job, _this.token).then(function(isStalled){
if(isStalled){
_this.emit('stalled', job);
return _this.processJob(job, true);
Expand Down Expand Up @@ -546,9 +546,15 @@ Queue.prototype.processJob = function(job, renew){
// 2) The lock renewer is called more seldom than the check for stalled
// jobs, so we can assume the job has been stalled and is already being processed
// by another worker. See #308
//
var lockRenewer = function(){
lockRenewId = _this.timers.set('lockRenewer', _this.LOCK_RENEW_TIME / 2, lockRenewer);
return job.takeLock(_this.token, renew).catch(function(err){
return job.takeLock(_this.token, renew).then(function(locked){
if(locked){
renew = true;
lockRenewId = _this.timers.set('lockRenewer', _this.LOCK_RENEW_TIME / 2, lockRenewer);
}
return locked;
}, function(err){
console.error('Error renewing lock ' + err);
});
};
Expand Down Expand Up @@ -606,7 +612,6 @@ Queue.prototype.processJob = function(job, renew){
});
}
});

};

/**
Expand Down

0 comments on commit 8a9e455

Please sign in to comment.