From f0668678313ab181e3e209029bde95689cc899b5 Mon Sep 17 00:00:00 2001 From: SH-Hong <73215772+code-xhyun@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:06:01 +0900 Subject: [PATCH] fix: modified it to exclude already run that should not be executed (#51) --- src/job/run.ts | 8 +++++++- src/pulse/resume-on-restart.ts | 13 ++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/job/run.ts b/src/job/run.ts index 2d56d67..fc7e8f8 100644 --- a/src/job/run.ts +++ b/src/job/run.ts @@ -85,7 +85,13 @@ export const run: RunMethod = async function (this: Job) { throw new JobError('Undefined job'); } - if (!this.pulse._resumeOnRestart && previousRunAt && this.pulse._readyAt >= previousRunAt) { + // on restart, skip the job if it's not time to run + if ( + !this.pulse._resumeOnRestart && + previousRunAt && + this.pulse._readyAt >= previousRunAt && + this.attrs.nextRunAt + ) { debug('[%s:%s] job resumeOnRestart skipped', this.attrs.name, this.attrs._id); resumeOnRestartSkipped = true; await jobCallback(undefined, 'skipped'); diff --git a/src/pulse/resume-on-restart.ts b/src/pulse/resume-on-restart.ts index 7b92834..8b77a3b 100644 --- a/src/pulse/resume-on-restart.ts +++ b/src/pulse/resume-on-restart.ts @@ -24,18 +24,13 @@ export const resumeOnRestart: ResumeOnRestartMethod = function (this: Pulse, res $or: [ { lockedAt: { $exists: true }, - $expr: { $eq: ['$runCount', '$finishedCount'] }, + nextRunAt: { $ne: null }, + $or: [{ $expr: { $eq: ['$runCount', '$finishedCount'] } }, { lastFinishedAt: { $exists: false } }], }, { - lockedAt: { $exists: true }, + lockedAt: { $exists: false }, lastFinishedAt: { $exists: false }, - }, - { - $and: [ - { lockedAt: { $exists: false } }, - { lastFinishedAt: { $exists: false } }, - { nextRunAt: { $lte: now } }, - ], + nextRunAt: { $lte: now, $ne: null }, }, ], },