Skip to content

Commit 2919083

Browse files
committed
fix(jobprocessor): improve checkIfJobIsStillAlive
1 parent d9deb8a commit 2919083

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/JobProcessor.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,15 @@ export class JobProcessor {
441441

442442
// check if the job is still alive
443443
const checkIfJobIsStillAlive = () => {
444-
// check every "this.agenda.definitions[job.attrs.name].lockLifetime"" (or at mininum every processEvery)
444+
// check every "this.agenda.definitions[job.attrs.name].lockLifetime / 2"" (or at mininum every processEvery)
445445
return new Promise((resolve, reject) =>
446446
setTimeout(() => {
447+
// when job is not running anymore, just finish
448+
if (!job.isRunning()) {
449+
resolve();
450+
return;
451+
}
452+
447453
if (job.isDead()) {
448454
reject(
449455
new Error(
@@ -454,13 +460,9 @@ export class JobProcessor {
454460
);
455461
return;
456462
}
457-
// when job is not running anymore, just finish
458-
if (!job.isRunning()) {
459-
resolve();
460-
return;
461-
}
463+
462464
resolve(checkIfJobIsStillAlive());
463-
}, Math.max(this.processEvery, this.agenda.definitions[job.attrs.name].lockLifetime))
465+
}, Math.max(this.processEvery, this.agenda.definitions[job.attrs.name].lockLifetime / 2))
464466
);
465467
};
466468

0 commit comments

Comments
 (0)