From 21b23a8739ecacd085c5decd1399f79b38f66409 Mon Sep 17 00:00:00 2001 From: Chris Germano Date: Sun, 6 Nov 2016 10:01:18 -0800 Subject: [PATCH] Fixes + protects against concurrency not being honored (#379) * 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 --- lib/agenda.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/agenda.js b/lib/agenda.js index 0f605f832..162ced564 100644 --- a/lib/agenda.js +++ b/lib/agenda.js @@ -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(); }