Skip to content

Commit

Permalink
fix(jobprocessor): improve checkIfJobIsStillAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed Oct 16, 2020
1 parent d9deb8a commit 2919083
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/JobProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,15 @@ export class JobProcessor {

// check if the job is still alive
const checkIfJobIsStillAlive = () => {
// check every "this.agenda.definitions[job.attrs.name].lockLifetime"" (or at mininum every processEvery)
// check every "this.agenda.definitions[job.attrs.name].lockLifetime / 2"" (or at mininum every processEvery)
return new Promise((resolve, reject) =>
setTimeout(() => {
// when job is not running anymore, just finish
if (!job.isRunning()) {
resolve();
return;
}

if (job.isDead()) {
reject(
new Error(
Expand All @@ -454,13 +460,9 @@ export class JobProcessor {
);
return;
}
// when job is not running anymore, just finish
if (!job.isRunning()) {
resolve();
return;
}

resolve(checkIfJobIsStillAlive());
}, Math.max(this.processEvery, this.agenda.definitions[job.attrs.name].lockLifetime))
}, Math.max(this.processEvery, this.agenda.definitions[job.attrs.name].lockLifetime / 2))
);
};

Expand Down

0 comments on commit 2919083

Please sign in to comment.