Skip to content

fix(ticker): claim due rows before delivering - #20

Merged
TheGreatAxios merged 1 commit into
cl-9447-cron-bound-tick-cost-and-make-every-accepted-schedule-firefrom
cl-9448-cron-claim-before-delivering-so-a-failed-tick-doesnt-re-fire
Sep 27, 2026
Merged

TheGreatAxios merged 1 commit into
cl-9447-cron-bound-tick-cost-and-make-every-accepted-schedule-firefrom
cl-9448-cron-claim-before-delivering-so-a-failed-tick-doesnt-re-fire

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

  • One short transaction locks the rows (FOR UPDATE SKIP LOCKED), decides which are due, and commits lastFiredAt on each row it will deliver. deliver() then runs after commit and outside the row lock.
  • A slow deliverer no longer holds locks against other replicas. A tick that dies mid-batch never re-fires what it claimed, so delivery is at most once per due minute. The README documents this.
  • onScheduleStopped and onScheduleWaiting fire after their change commits.
  • New e2e tests: a tick is killed mid-batch (its Postgres sessions are terminated and the fifth delivery never returns), and every row is still delivered at most once. Three concurrent tickers deliver each of 21 rows exactly once through createRunTriggerCronDeliver. The three-ticker test replaces the two-ticker one.

Stacked on #19.

Verification

bun run check, build, test:e2e against local Postgres, and the Node pack smoke pass. The kill test fails on #19 first.

Closes CL-9448

One short transaction locks the rows, decides which are due and commits
lastFiredAt on each it will deliver. deliver() then runs after commit and
outside the row lock, so a slow deliverer blocks no replica and a tick
that dies mid-batch never re-fires what it claimed: delivery is at most
once per due minute, as the README now says. Stop and waiting callbacks
fire after their change commits. New e2e tests kill a tick mid-batch and
race three tickers; the three-ticker test replaces the two-ticker one.

Closes CL-9448
@TheGreatAxios
TheGreatAxios added this pull request to stack #16 September 27, 2026 02:27
@TheGreatAxios
TheGreatAxios merged commit 321edf6 into main Sep 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant