Skip to content

Commit 5bc123a

Browse files
committed
fix(locking): ensure jobs are not locked too greedy
1 parent 8cd1c31 commit 5bc123a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/utils/process-jobs.js

+8
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ module.exports = function(extraJob) {
171171
// 3. Queue the job to actually be run now that it is locked
172172
// 4. Recursively run this same method we are in to check for more available jobs of same type!
173173
if (job) {
174+
// Before en-queing job make sure we haven't exceed our lock limits
175+
if (!shouldLock(name)) {
176+
debug('lock limit reached before job was returned. Releasing lock on [%s]', name);
177+
job.attrs.lockedAt = null;
178+
self.saveJob(job);
179+
return;
180+
}
181+
174182
debug('[%s:%s] job locked while filling queue', name, job.attrs._id);
175183
self._lockedJobs.push(job);
176184
definitions[job.attrs.name].locked++;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hokify/agenda",
3-
"version": "3.1.4",
3+
"version": "3.1.5",
44
"description": "Light weight job scheduler for Node.js",
55
"main": "index.js",
66
"files": [

0 commit comments

Comments
 (0)