Repository navigation
Cron triggers, in standalone workerd and in a cluster - #8235
Conversation
There was a problem hiding this comment.
Superseded by the review of
4cebbde5.
This review, of 1eda2e62
💬 Approved with comments — Nothing found makes this unsafe to merge. One WARNING: the README's list of supported Wrangler fields is now wrong because it omits triggers.crons. Two INFO notes: an inaccurate doc comment and a possible flaky parse in the test.
Findings: 1 warning · 2 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8235.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Documentation] README.md lists the supported Wrangler fields and says any other is an error, but omits the newly supported `triggers.crons` (requires --experimental)
- **File:** README.md:115
## INFO (2)
### [Code Quality] Test output parser can drop a SCHEDULED line split across data chunks
- **File:** src/workerd/server/tests/cron/cron-test.mjs:69
### [Code Quality] MAX_LOOKAHEAD_DAYS comment understates how often the full walk runs
- **File:** src/workerd/server/server/cron.rs:39
📋 Code Quality: 💬 2 info
Logic looks correct. Two minor notes: a test output parser and an inaccurate doc comment.
Recommendation: 💬 Optional Nits
- [INFO] Test output parser can drop a SCHEDULED line split across data chunks (
src/workerd/server/tests/cron/cron-test.mjs:69) - [INFO] MAX_LOOKAHEAD_DAYS comment understates how often the full walk runs (
src/workerd/server/server/cron.rs:39)
View full review
src/workerd/server/tests/cron/cron-test.mjs:63-70: the parser movescalls.consumedpast text that may still hold an unfinishedSCHEDULED {...}line. When the rest of that line arrives, the match starts beforeconsumedand is thrown away. stdout and stderr also write into the same buffer, so their output can interleave mid-line.src/workerd/server/server/cron.rs:38-39: the comment says only an unsatisfiable expression pays the full 146,097-day walk, "once, at arm time". In factplan()walks every expression on every/planrequest, two or three times per alarm. A script that pairs an unsatisfiable expression with satisfiable ones pays the full walk on every request.
📝 Documentation: ⚠️ 1 warning
README's list of supported Wrangler fields is now wrong
Recommendation: 📝 Minor Comments
- [WARNING] README.md lists the supported Wrangler fields and says any other is an error, but omits the newly supported
triggers.crons(requires --experimental) (README.md:115)
View full review
README.md:111-115lists the Wrangler fieldsworkerd serveaccepts and ends with "any other field is an error". This pull request makestriggers.cronsa supported field (with--experimental), so the README now gives users a false statement. Addtriggers.cronsnext tokv_namespacesin the--experimentallist.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found. workerd:cron-plan is bound only inside the built-in workerd:cron worker, so user Workers cannot reach it, and it parses its query parameters defensively. The target script is looked up through the TARGETS map using the name in the object's own storage. The cron parser checks field ranges and steps, and its lookahead walk is bounded. Both the capnp and wrangler paths require --experimental.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues in the lines this pull request changes.
⚡ Performance: ✅ LGTM
No performance issues found. Each occurrence adds a few plan fetches and storage writes, and each scheduled script gets one arm call at startup. The per-object state stays bounded.
Reviewed commit: 1eda2e62
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8235 +/- ##
==========================================
- Coverage 65.23% 65.19% -0.04%
==========================================
Files 757 758 +1
Lines 190745 190879 +134
Branches 30110 30110
==========================================
+ Hits 124424 124436 +12
- Misses 48796 48919 +123
+ Partials 17525 17524 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
For each of these, if reasonably possible, an example in the |
A config runs cron triggers with the Worker `bundled = "/workerd/cron.js"`: each schedule is a Durable Object whose alarm is the whole scheduler, so an occurrence runs once however many instances of a cluster run the config, and the alarm fails over with the object. Its header documents the config as an interface, as kv.js does: the `Schedule` class on a local disk, and `CRONS`, each schedule's expressions keyed by a service binding to the Worker they run. A missed occurrence runs once, late; a failed one retries with backoff, never past the next occurrence. Expressions are Cloudflare's dialect, read as its parser (saffron) reads them, ported to JavaScript so the module needs nothing native: weekdays 1-7 from Sunday, L, W and #. A descending range, `*` inside a list and an expression that never matches are refused. The module checks its expressions when it loads, so a bad one fails the config. workerd sends each Worker using the module one scheduled event at startup, which arms its schedules, and keeps serving until it drains, sockets or not. The module calls its targets with Fetcher.scheduled(), which needs service_binding_extra_handlers. tests/cron: the parser and plan; and `workerd serve` armed with no request or socket, each minute once, a failed first attempt retried with the same scheduledTime.
A wrangler config's triggers.crons become the schedule of the Worker `<name>-cron`, the built-in module /workerd/cron.js, with its objects in .wrangler/state/workerd/cron/. Like kv_namespaces they need --experimental, and a deployment cannot have them yet.
cluster-cron.wd-test is cluster-test.wd-test with a cron Worker running main's scheduled() every minute, which records each occurrence in a Counter. After the first, the schedule object's owner (its own.json in the bucket) is SIGKILLed, and a survivor runs the next minute, once. The suite is split by test name (CLUSTER_TESTS) into cluster-test and cluster-cron-test, which waits real minutes, so each stays under the 240 s eternal timeout.
There was a problem hiding this comment.
Superseded by the review of
e490d098.
This review, of 4cebbde5
💬 Approved with comments — Nothing found makes this unsafe to merge. The earlier README WARNING is fixed, and the only remaining notes are two INFO items in test files.
Findings: 2 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
No correctness problems; two low-impact test-file notes.
Recommendation: 💬 Optional Nits
- [INFO] Test output parser can drop a SCHEDULED line split across data chunks (
src/workerd/server/tests/cron/cron-test.mjs:86) - [INFO] Duplicate section number 13 in the cluster-test header (
src/workerd/server/tests/cluster/cluster-test.mjs:40)
View full review
I found no correctness problems in the retry and alarm logic in cron.js, in server/cron.rs and run.rs (arming starts after the early return, stops on drain, and is skipped under workerd test), or in the order of services in wrangler.rs. Two notes on test files:
tests/cron/cron-test.mjs: the output parser can drop aSCHEDULED {...}line that arrives split across data chunks.tests/cluster/cluster-test.mjs: the header gives the new cron entry the number 13, which the KV entry already uses.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found. Both the capnp and the wrangler paths require --experimental, and a deployment with triggers.crons is refused. The parser checks field ranges and steps, and its lookahead walk is bounded. The scheduled target comes from the config's own CRONS map.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
The README's list of supported Wrangler fields now includes triggers.crons.
Reviewed commit: 4cebbde5
A chunk of output can end mid-line, and the old parser skipped a SCHEDULED line split across two chunks. Parse each stream's complete lines instead.
A Worker's scheduled() handler run every minute and every five minutes by the bundled module /workerd/cron.js.
|
[AI] Added |
There was a problem hiding this comment.
Superseded by the review of
3a51c5f5.
This review, of e490d098
💬 Approved with comments — Nothing makes this unsafe to merge. The parser fix holds, the new sample is consistent with the module, and the only open note is a duplicate section number in a test header comment (INFO).
Findings: 1 info
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
The parser fix holds. One INFO remains: a duplicate section number in a test header.
Recommendation: 💬 Optional Nits
- [INFO] Duplicate section number 13 in the cluster-test header comment (
src/workerd/server/tests/cluster/cluster-test.mjs:40)
View full review
- The test output parser now buffers a partial line per stream and parses only complete lines (
cron-test.mjs:83-95), so the earlier split-line note is fixed. samples/cron/config.capnpmatches the shape thatcron.jsandwrangler.rsemit.tests/cluster/cluster-test.mjs:40: the cron entry in the header is numbered 13, but the KV entry already uses 13.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found. The expressions, the scheduled targets and the bindings all come from the operator's own config. The parser's lookahead walk is bounded, and both config paths require --experimental.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
The new samples/cron/README.md is accurate and follows the format of the existing samples.
Reviewed commit: e490d098
On Windows the path's backslashes were read as escapes in the capnp string, so the config failed to parse.
There was a problem hiding this comment.
Superseded by the review of
17181f17.
This review, of 3a51c5f5
✅ Approved — The Windows path quoting fix is correct, and the rest of the pull request has not changed since the earlier review, which found nothing unsafe to merge. One earlier minor note stays open.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues.
📋 Code Quality: ✅ LGTM
cron-test.mjs:35 now quotes the store path with JSON.stringify. Capnp text literals accept JSON's backslash escapes, so a Windows path now parses. One earlier INFO note, the duplicate section number in the cluster-test header comment, remains open.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 3a51c5f5
There was a problem hiding this comment.
Superseded by the review of
c05d07e2.
This review, of 17181f17
✅ Approved — The Windows path quoting fix is correct, and the rest of the pull request has not changed since the earlier review, which found nothing unsafe to merge. One earlier minor note stays open.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues.
📋 Code Quality: ✅ LGTM
cron-test.mjs:35 now quotes the store path with JSON.stringify. Capnp text literals accept JSON's backslash escapes, so a Windows path now parses. One earlier INFO note, the duplicate section number in the cluster-test header comment, remains open.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 17181f17 — same changes as 3a51c5f5, so this is that commit's review (no new review was run; line numbers are as of 3a51c5f5)
- L-nW on a Saturday target ran on both the Friday before and the Monday after; it now runs on the Friday, as saffron does. - nW for a day past the month's end (31W in September) ran on the 30th when that was a Friday; it now skips the month, as saffron does. - 1#2#3 was read as 1#2; it is refused. - A CRONS name with no service binding failed every occurrence at run time; it now fails the config when it loads. Expressions are parsed once there instead of at every arm and alarm. - Schedules, and cron Workers, are armed in parallel, so one failing Worker no longer delays the others' first run. - Only a Worker whose main module is /workerd/cron.js is armed at startup, not one that merely imports it. - The retry comment now matches the code; the min() clamp could never apply.
There was a problem hiding this comment.
Superseded by the review of
660a6519.
This review, of c05d07e2
✅ Approved — The fixes in cron.js and cron.rs since the last review are correct, the one earlier note is fixed, and nothing new is unsafe to merge.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Expressions come from the operator's config, not from request data. Parsing uses anchored regexes and bounded loops. The scheduled event goes only to the Worker's own service binding.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues.
📋 Code Quality: ✅ LGTM
I hand-checked the parser fixes in cron.js (L-nW, a nW day past the end of the month, 1#2#3, L-31) against the unit test expectations, and they match. The retry and arming logic in cron.js is consistent, and so is startup arming in cron.rs. The cluster test split has no overlap. The header comment in cluster-test.mjs now numbers its sections correctly.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found in the files changed since the last review.
Reviewed commit: c05d07e2
piscisaureus
left a comment
There was a problem hiding this comment.
[🤖] Test gaps found while reviewing (the line comments cover the bugs):
- No test restarts a server. A missed occurrence is handled correctly (SIGKILL after 20:19, restart at 20:21:10: 20:20 ran once, 70 s late, 20:21 was folded into it, 20:22 ran normally), but deleting the keep-existing-alarm early return in
arm()would drop every missed occurrence and no test would fail. A stop/restart case incron-test.mjswould cover it. - Parser mutants that every unit test survives: the
t <= lastguard; theWarm for a month ending on a Sunday (→ Friday); both Monday arms ofL-nW;d + 7 > lastchanged to>=; the descending-range check (only caught incidentally by "never matches"); andstep > 1 ? f.max : firstchanged tofirst. 30/15from 12:46 gives 13:30 under either reading of a step; starting from 12:31 and expecting 12:45 would tell them apart.31Win September 2026 can't exercise the month-end guard, since the 30th is a Wednesday.- The cluster cron test returns as soon as it sees 2 ticks, so a duplicate arriving a second later goes unseen; waiting a little past the second tick would catch one.
- Not covered at all: retries after eviction and a restart during a pending retry (see the comment on
#owed), and a handler that outlives the alarm limit.
- Retries are stored with the schedule, not held in memory: an idle object is evicted 10 s after its last request, so from the fourth retry on, and after any restart, the retry was dropped. - Each run gets 10 minutes, under workerd's alarm limit, and counts as failed past that; the expressions due at one time run at once. One schedule's runs never overlap, and an occurrence that comes due during a run is skipped; this is now documented. - A clock stepped back can no longer bring an occurrence round twice. - Startup arms schedules with allSettled, so one failing schedule no longer cancels the others; Rust retries arming for about 31 s, past the cluster lease, and logs each failure. - N/1 now reads as N to the end of the field, as saffron does. - L-nW with a target before the 1st (L-28W in a 28-day February) matches nothing, as saffron does, and L-29W in February is refused. - A CRONS value that is not a list fails with a clear error, and duplicate expressions run once. - wrangler refuses a Worker named CRONS or SCHEDULE, which would collide with the cron Worker's own bindings. - Tests: a pending retry and a missed occurrence across restarts; the cluster cron test waits past the second tick for a duplicate; parser cases for each arm a mutant could remove; refusals of 5,* and 0,30-10 in place of *,5, which saffron refuses too. - Sample: corrected the storage comment, and bazel run passes the disk's full path.
There was a problem hiding this comment.
Superseded by the review of
b923ed30.
This review, of 660a6519
✅ Approved — Every point raised in the discussion is fixed at this commit, and the code changed since the last review introduces nothing unsafe to merge.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Cron expressions come from the operator's config, not from request data. The parser's loops are bounded and its regexes are anchored. The scheduled event goes only to each Worker's own service binding.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
The code changed since the last review is correct: cron.js, cron.rs, wrangler.rs, the tests and the sample. The parser and retry changes match their test fixtures. These points from the discussion are fixed: the N/1 step, the retries stored with the schedule, the arms run with allSettled, the L-nW guard for day 0, the 10-minute run limit, the clock step-back guard, the CRONS validation and dedupe, the refused binding names, and the longer, logged startup arming.
⚡ Performance: ✅ LGTM
The next() walk is bounded. It runs to full length only for an expression that never matches, and those are refused once, at load. plan() costs one next() per expression per alarm. Startup arming is a fixed number of retries with backoff.
📝 Documentation: ✅ LGTM
The sample README and config comments match the code. The README gives an absolute disk path for bazel run.
Reviewed commit: 660a6519
The cron tests waited for real minutes and polled with sleeps. Each now waits for one occurrence at most per phase, and on output rather than a timer: - cron-test folds its two clock-bound cases into one: the first occurrence fails, workerd is killed before the retry, and the retry runs once it restarts, which also covers keeping a pending alarm at startup. Its until() resolves as workerd prints, not on a poll. - The cluster cron test watches each node's stderr for the tick its handler logs (ClusterNode.waitForStderr); the node that logs it is the schedule's owner, so the bucket lookup and the Counter's /tick and /ticks routes go. Also rustfmt in wrangler.rs.
There was a problem hiding this comment.
Superseded by the review of
5439dc53.
This review, of b923ed30
💬 Approved with comments — Every finding from the discussion is fixed. The only new notes are two INFO items about test timing and a test comment.
Findings: 2 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
The changes since the last review are correct. There are two test-only notes: a narrow flake window in the cluster cron test, and a comment in the restart test that overstates what it covers.
Recommendation: 💬 Optional Nits
- [INFO] The cluster cron test can flake: SIGKILL right after
TICKmay land before the next alarm is stored, so a survivor runs the same occurrence again. (src/workerd/server/tests/cluster/cluster-test.mjs:2826) - [INFO] The restart test comment claims the stored retry runs after the restart, but the assertion passes whether the restart runs a stored retry or runs the occurrence again. (
src/workerd/server/tests/cron/cron-test.mjs:136)
View full review
src/workerd/server/tests/cluster/cluster-test.mjs:2826: the owner is SIGKILLed as soon asTICKis logged. That can land beforealarm()stores the next alarm (cron.js, after the handler returns), so a survivor runs the same occurrence again andseencomes out as[t, t]. This is a rare flake.src/workerd/server/tests/cron/cron-test.mjs:136: the comment says the kill comes before the retry and that the stored retry runs after the restart. The kill often lands before the retry is stored. The assertion passes whether the restart runs a stored retry or runs the occurrence again, so the test doesn't tell the two paths apart.
✅ All other checks passed
🔒 Security: ✅ LGTM
Cron expressions come from the operator's config, not from request data. Each scheduled event goes only to the Worker's own service binding.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
next()is bounded, and the load-time check refuses any expression that never matches.plan()costs onenext()per expression per alarm.- Startup arming retries a fixed number of times, with backoff.
- The run timer is cleared in
finally.
📝 Documentation: ✅ LGTM
The sample README and the config comments match the code.
Reviewed commit: b923ed30
As KV does, an optional TEST_CLOCK binding enables POST /clock?advance= on the cron Worker: it moves this process's planning clock and re-arms every schedule by it, while alarms keep the real clock. A test moves the clock to a second before a minute and sees it run a second later. arm() now waits out a run in progress, so an arm can no longer race the alarm it replaces, and /clock returns only once runs have finished. The cluster test needs that: it killed the owner mid-run, and the survivor rightly ran the occurrence again. cron-test now takes seconds, not a minute; the cluster cron test takes about the 20 s lease takeover, not two minutes. Both match the occurrence they set up, so a real minute passing before the clock moves is ignored.
There was a problem hiding this comment.
Superseded by the review of
17a315c4.
This review, of 5439dc53
💬 Approved with comments — No correctness, security or performance problems found. The one remaining note is an INFO: the restart test's comment claims more than the test checks.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
One INFO is still open: the restart test can't tell a stored retry from a rerun of the occurrence. The cluster test flake is fixed.
Recommendation: 💬 Optional Nits
- [INFO] Restart test comment says the stored retry runs after the restart, but the assertion passes the same way if the occurrence reruns instead. (
src/workerd/server/tests/cron/cron-test.mjs:159)
View full review
src/workerd/server/tests/cron/cron-test.mjs:159: the comment says the stored retry runs after the restart. Butattemptsis in-process, so the first call after the restart is alwaysn: 1. A stored retry and a rerun of the occurrence therefore give the sameruns().- The cluster cron flake is fixed.
clock(nodes, 0)before the kill waits until the owner has stored its next alarm.
✅ All other checks passed
🔒 Security: ✅ LGTM
/clock returns 404 unless TEST_CLOCK is bound. Configs generated from wrangler never bind it. Cron expressions come from the operator's config, and scheduled events go only to the Worker's own service binding.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
No performance concerns in the changed code.
📝 Documentation: ✅ LGTM
The sample README and the config comments match the code.
Reviewed commit: 5439dc53
Right after start, a node's first arm can reach a peer that is not yet listening; workerd retries its startup arm for that, but the test's first /cron-clock failed at once. The test now waits for each node's "cron ... armed" log, which workerd now writes, and moves the clock to just before the next minute while the owner lives, then kills it: a survivor adopts the overdue alarm when the lease runs out, with no request to the dead owner.
There was a problem hiding this comment.
Superseded by the review of
c1408b9d.
This review, of 17a315c4
💬 Approved with comments — No correctness, security or performance problems found. The one remaining note is an INFO: the restart test's comment claims more than the test checks.
Findings: 1 info
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
One INFO carried over: the restart test's comment overstates what its assertion checks. Nothing new in cron.rs or cluster-test.mjs.
Recommendation: 💬 Optional Nits
- [INFO] Restart test comment says the stored retry runs after the restart, but the assertion passes the same way if the occurrence reruns instead. (
src/workerd/server/tests/cron/cron-test.mjs:159)
View full review
src/workerd/server/tests/cron/cron-test.mjs:159: the comment says the stored retry runs after the restart. Butattemptslives in the worker process, so the first call after the restart is alwaysn: 1, which fails, and the in-process retry then logsn: 2. A stored retry and a full rerun of the occurrence therefore give the sameruns().server/cron.rsandtests/cluster/cluster-test.mjs(changed since the last review): no problems found.
✅ All other checks passed
🔒 Security: ✅ LGTM
Nothing in the files changed since the last review affects security.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
Startup arming makes a bounded number of attempts, with doubling backoff, per cron Worker. Arms run in parallel through Promise.allSettled, and the run timeout timer is cleared in finally.
📝 Documentation: ✅ LGTM
The sample README and the config comments match the code.
Reviewed commit: 17a315c4
After a run, the next alarm was planned from the later of the clock and the occurrence, so that a clock stepped back never brings the occurrence round again. That also put the retry's backoff after the occurrence: a clock 50 s behind it delayed a 4 s retry by 50 s. plan() now searches for the next occurrence after both, and times a retry from the clock. cron-test caught it: after a restart drops the test clock's skew, the retry was due almost a minute late.
Its attempts are counted in memory, so it cannot tell a stored retry from the occurrence run afresh; it shows the restart drops neither.
|
[AI] @piscisaureus, on the test gaps:
The cron tests no longer wait for real minutes or sleep. A |
There was a problem hiding this comment.
✅ Approved — No correctness, security or performance problems in the code changed since the last review, and the one earlier note (the restart test's comment) is fixed.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
wrangler.rsbuilds the generated config throughserde_jsonand the capnp builder, so no expression text is pasted into config source.- The
/clockendpoint exists only when theTEST_CLOCKbinding is set. - The parser's lookahead is bounded, and an expression that never matches is refused when the module loads.
- The startup scheduled event goes only to Workers whose module is
/workerd/cron.js.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
The restart test in cron-test.mjs now claims only that a restart does not drop the occurrence. Its assertion [first, { ...first, n: 2 }] passes whether the restart runs the stored retry or runs the occurrence again, so the claim and the check match.
In cron.js, a stored retry (owed) survives eviction and restart. arm() keeps an existing alarm that is no later than the planned one, and the alarm is set in clock time adjusted by skew. The W, L-nW and LW day arms give the dates the unit fixtures expect. #run clears its timeout in finally.
⚡ Performance: ✅ LGTM
No performance concerns in the changed code.
📝 Documentation: ✅ LGTM
The sample README and the config comments match the code.
Reviewed commit: c1408b9d
piscisaureus
left a comment
There was a problem hiding this comment.
[🤖] All points from my review are addressed. LGTM.
Part of merging celld into workerd, following #8172 (KV). Adds cron triggers: a Worker's
scheduled()handler runs on a schedule, in standalone workerd or in a cluster, once per occurrence however many instances run the config.Like KV, cron is plain config around a bundled module,
bundled = "/workerd/cron.js". Its header documents the config as an interface for config generators: aScheduleDurable Object class on a local disk, andCRONS, each schedule's expressions keyed by a service binding to the Worker they run.triggers.cronsin a wrangler.json given toworkerd serveemits it. Requires--experimental. Nothing changes for configs that don't use the module, Miniflare's included.How it works: each schedule is one Durable Object, whose alarm is the scheduler, so in a cluster the schedule fails over with the object. workerd sends each Worker that uses the module one scheduled event at startup, which arms its schedules. A missed occurrence runs once, late; a failed one retries with backoff, never past the next occurrence.
Expressions are Cloudflare's dialect, read the way its parser (saffron) reads them, ported to JavaScript so the module needs nothing native: weekdays 1-7 from Sunday,
L,W,#, in UTC. Two of saffron's readings are refused rather than copied (a descending range, which it wraps one value too far, and*inside a list), as is an expression that never matches. The module checks its expressions when it loads, so a bad one fails the config at startup.Tests: the parser and plan; a standalone server running each minute once, a failed attempt retried, and a bad expression refused; and a cluster test where the schedule object's owner is SIGKILLed and a survivor runs the next minute once. An earlier version of this design ran on a 3-node cluster on R2 for 16 minutes through two owner kills, with every minute exactly once.