Repository navigation
[Phase 3] Cloudflare scheduler adapter - #3
Conversation
Adds @pegma/scheduler-cloudflare with explicit cron route dispatch, scheduledTime and waitUntil handling, unit coverage, and real local D1 fixture tests for restart, overlap, and checkpoint cycles.
|
@codex review |
CI on Node 22 failed because the lockfile omitted a workers-types version required by the Vitest Workers pool dependency tree.
There was a problem hiding this comment.
Pull request overview
Implements Phase 3 by introducing @pegma/scheduler-cloudflare, a thin Cloudflare Cron Trigger adapter that dispatches a host-supplied cron route map into core @pegma/scheduler’s runScheduled, plus adds a Workers Vitest pool setup for real local D1 coverage and updates repository docs/scripts accordingly.
Changes:
- Add
@pegma/scheduler-cloudflarepackage with explicit cron→task routing and optionalwaitUntilwiring. - Add dedicated D1 Vitest configuration and TypeScript project config for Workers/D1 tests; split Node vs D1 test runs.
- Update docs (testing, Cloudflare guide, architecture, plan) and repo scripts to reflect Phase 3 completion.
Reviewed changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.d1.config.ts | Adds Workers Vitest pool configuration for running *.d1.test.ts tests against real local D1. |
| vitest.config.ts | Excludes *.d1.test.ts from the default (Node) test run. |
| tsconfig.test.json | Excludes D1 tests from the Node test typecheck; includes the new Vitest D1 config file. |
| tsconfig.json | Adds TS project reference for the new scheduler-cloudflare package. |
| tsconfig.d1-test.json | Adds a dedicated TS config for typechecking D1/Workers tests. |
| test/wrangler.d1.toml | Provides Wrangler config for the Workers Vitest pool D1 binding. |
| test/d1-worker.ts | Minimal Worker entrypoint required by Wrangler for the D1 test harness. |
| README.md | Updates repo status to Phase 3 and documents split test commands. |
| packages/scheduler-cloudflare/tsconfig.json | TypeScript build config for the new package, excluding tests from builds. |
| packages/scheduler-cloudflare/src/index.ts | Implements the Cloudflare scheduled-event dispatch adapter over core Scheduler. |
| packages/scheduler-cloudflare/src/index.test.ts | Adds unit tests for routing, scheduledTime conversion, and waitUntil behavior. |
| packages/scheduler-cloudflare/src/fixture.d1.test.ts | Adds D1 integration tests via Workers pool to validate durability/overlap/checkpoint behavior. |
| packages/scheduler-cloudflare/README.md | Package documentation and local development notes for Cloudflare scheduled dispatch. |
| packages/scheduler-cloudflare/package.json | Package manifest/exports/scripts for @pegma/scheduler-cloudflare. |
| packages/scheduler-cloudflare/LICENSE | Adds license file for the new package. |
| package.json | Adds D1 test scripts and Cloudflare dev dependencies used by the Workers pool. |
| package-lock.json | Lockfile updates for newly added Cloudflare-related dependencies. |
| docs/TESTING.md | Documents Phase 3 adapter coverage and the D1 test layer. |
| docs/PROJECT_PLAN.md | Marks Phase 3 complete and updates status wording accordingly. |
| docs/CLOUDFLARE.md | Updates Cloudflare adapter guidance and D1 test instructions. |
| docs/ARCHITECTURE.md | Updates architecture description to reflect the implemented Cloudflare adapter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d78a0500d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
Catch out-of-range Date conversions with a clear TypeError, and align the Workers pool compatibility date with the locked workerd binary.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ddcbbe6d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const result = await options.scheduler.runScheduled(taskId, { | ||
| scheduledFor, | ||
| invocationId: newInvocationId(), | ||
| }); |
There was a problem hiding this comment.
Continue dispatching after one routed task rejects
When an earlier task's runScheduled call rejects—for example, because that task's stored state is malformed or its Store claim throws—this await exits the loop, so every later task mapped to the same cron is silently skipped even though its durable state may be healthy. Since the adapter supports multiple independent tasks per Cron Trigger, continue invoking the remaining routes and aggregate/rethrow infrastructure errors after all tasks have been attempted.
Useful? React with 👍 / 👎.
Summary
Implements Phase 3 of
docs/PROJECT_PLAN.md:@pegma/scheduler-cloudflare.runScheduledcontroller.scheduledTime→ trustedscheduledForwaitUntilregistration on the execution context--test-scheduled,/__scheduled, persist, Docker 30s driverPhase 3 exit criteria
@pegma/scheduler-cloudflareScheduledController.cronthrough explicit typed route mapscheduledTimeandwaitUntilbehaviorTest evidence
Residual risks
wrangler devprocess-kill e2e; Docker volume persistence is documented for hosts.0.0.0); Phase 4 is consumer integration.