Skip to content

Commit

Permalink
fix: modified it to exclude already run that should not be executed (#51
Browse files Browse the repository at this point in the history
)
  • Loading branch information
code-xhyun authored Aug 16, 2024
1 parent 6299f37 commit f066867
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/job/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 4 additions & 9 deletions src/pulse/resume-on-restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
],
},
Expand Down

1 comment on commit f066867

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 53%
56.34% (582/1033) 40.57% (127/313) 51.57% (82/159)

Pulse Test Report

Tests Skipped Failures Errors Time
63 0 💤 0 ❌ 0 🔥 10.159s ⏱️

Please sign in to comment.