Skip to content

Commit

Permalink
revert cron schedule regression (#3627)
Browse files Browse the repository at this point in the history
  • Loading branch information
fubhy authored Sep 18, 2024
1 parent 5ff6485 commit f0d8ef1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-deers-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Revert cron schedule regression
12 changes: 3 additions & 9 deletions packages/effect/src/internal/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,12 @@ 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)) {
const next = now
const start = beginningOfMinute(next)
const end = endOfMinute(next)
return core.succeed([
[false, [next, start, end]],
[start, end],
ScheduleDecision.continueWith(Interval.make(start + 60000, end + 60000))
])
next = now
}

const next = Cron.next(cron, date).getTime()
next = Cron.next(cron, date).getTime()
const start = beginningOfMinute(next)
const end = endOfMinute(next)
return core.succeed([
Expand Down
11 changes: 5 additions & 6 deletions packages/effect/test/Schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,26 +572,25 @@ describe("Schedule", () => {
}))
})
describe("cron-like scheduling - repeats at point of time (minute of hour, day of week, ...)", () => {
it.effect("recur every minute after initial interval using cron", () =>
it.effect("recur every second minute using cron", () =>
Effect.gen(function*($) {
const ref = yield* $(Ref.make<ReadonlyArray<string>>([]))
yield* $(TestClock.setTime(new Date(2024, 0, 1, 0, 0, 35).getTime()))
const schedule = Schedule.cron("* * * * *")
const schedule = Schedule.cron("*/2 * * * *")
yield* $(
TestClock.currentTimeMillis,
Effect.tap((instant) => Ref.update(ref, Array.append(format(instant)))),
Effect.repeat(schedule),
Effect.fork
)
yield* $(TestClock.adjust("5 minutes"))
yield* $(TestClock.adjust("8 minutes"))
const result = yield* $(Ref.get(ref))
const expected = [
"Mon Jan 01 2024 00:00:35",
"Mon Jan 01 2024 00:01:00",
"Mon Jan 01 2024 00:02:00",
"Mon Jan 01 2024 00:03:00",
"Mon Jan 01 2024 00:04:00",
"Mon Jan 01 2024 00:05:00"
"Mon Jan 01 2024 00:06:00",
"Mon Jan 01 2024 00:08:00"
]
assert.deepStrictEqual(result, expected)
}))
Expand Down

0 comments on commit f0d8ef1

Please sign in to comment.