Skip to content

Commit 8ef9510

Browse files
committed
fix(cron): guard against firing a sooner-than-peeked job after a late wake
1 parent a51c086 commit 8ef9510

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎packages/core/src/cron/service.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ const make = Effect.gen(function* () {
6161
const job = yield* dequeueJob()
6262
if (!job) continue
6363

64+
if (job.id !== top.id) {
65+
// A sooner job was inserted during the sleep and won the heap head.
66+
// Re-queue the job we just popped and re-iterate instead of firing early.
67+
yield* insertJob(job)
68+
continue
69+
}
70+
6471
const current = yield* Clock.currentTimeMillis
6572

6673
if (current >= job.expiresAt) continue

0 commit comments

Comments
 (0)