Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit f066867

Browse files
authored
fix: modified it to exclude already run that should not be executed (#51)
1 parent 6299f37 commit f066867

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/job/run.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,13 @@ export const run: RunMethod = async function (this: Job) {
8585
throw new JobError('Undefined job');
8686
}
8787

88-
if (!this.pulse._resumeOnRestart && previousRunAt && this.pulse._readyAt >= previousRunAt) {
88+
// on restart, skip the job if it's not time to run
89+
if (
90+
!this.pulse._resumeOnRestart &&
91+
previousRunAt &&
92+
this.pulse._readyAt >= previousRunAt &&
93+
this.attrs.nextRunAt
94+
) {
8995
debug('[%s:%s] job resumeOnRestart skipped', this.attrs.name, this.attrs._id);
9096
resumeOnRestartSkipped = true;
9197
await jobCallback(undefined, 'skipped');

src/pulse/resume-on-restart.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ export const resumeOnRestart: ResumeOnRestartMethod = function (this: Pulse, res
2424
$or: [
2525
{
2626
lockedAt: { $exists: true },
27-
$expr: { $eq: ['$runCount', '$finishedCount'] },
27+
nextRunAt: { $ne: null },
28+
$or: [{ $expr: { $eq: ['$runCount', '$finishedCount'] } }, { lastFinishedAt: { $exists: false } }],
2829
},
2930
{
30-
lockedAt: { $exists: true },
31+
lockedAt: { $exists: false },
3132
lastFinishedAt: { $exists: false },
32-
},
33-
{
34-
$and: [
35-
{ lockedAt: { $exists: false } },
36-
{ lastFinishedAt: { $exists: false } },
37-
{ nextRunAt: { $lte: now } },
38-
],
33+
nextRunAt: { $lte: now, $ne: null },
3934
},
4035
],
4136
},

0 commit comments

Comments
 (0)