Skip to content

Commit

Permalink
Fixes + protects against concurrency not being honored (#379)
Browse files Browse the repository at this point in the history
* throw an error if done callback called more than once. prevent negative running and locked counters that cause concurrency to not be honored

* throw an error if done callback called more than once. prevent negative running and locked counters that cause concurrency to not be honored
  • Loading branch information
netslayer authored and rschmukler committed Nov 6, 2016
1 parent 72101bc commit 21b23a8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/agenda.js
Expand Up @@ -675,11 +675,13 @@ function processJobs(extraJob) {
if (err && !job) throw(err)
var name = job.attrs.name;

if (self._runningJobs.indexOf(job) == -1) throw("callback already called - job " + name + " already marked complete");

self._runningJobs.splice(self._runningJobs.indexOf(job), 1);
definitions[name].running--;
if (definitions[name].running > 0) definitions[name].running--;

self._lockedJobs.splice(self._lockedJobs.indexOf(job), 1);
definitions[name].locked--;
if (definitions[name].locked > 0) definitions[name].locked--;

jobProcessing();
}
Expand Down

0 comments on commit 21b23a8

Please sign in to comment.