Skip to content

Commit

Permalink
fix double firing of schedules at initial interval
Browse files Browse the repository at this point in the history
  • Loading branch information
fubhy committed Sep 17, 2024
1 parent cd75658 commit dee5f58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-comics-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Fixed double firing of cron schedules in cases where the current time matched the initial interval.
12 changes: 2 additions & 10 deletions packages/effect/src/internal/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,10 @@ export const cron = (expression: string | Cron.Cron): Schedule.Schedule<[number,

const cron = parsed.right
const date = new Date(now)

let next: number
if (initial && Cron.match(cron, date)) {
next = now
} else {
const result = Cron.next(cron, date)
next = result.getTime()
}

const next = initial && Cron.match(cron, date) ? now : Cron.next(cron, date).getTime()
const start = beginningOfMinute(next)
const end = endOfMinute(next)
const interval = Interval.make(start, end)
const interval = initial ? Interval.make(start + 60000, end + 60000) : Interval.make(start, end)
return core.succeed([
[false, [next, start, end]],
[start, end],
Expand Down

0 comments on commit dee5f58

Please sign in to comment.