Skip to content

[Phase 3] Cloudflare scheduler adapter - #3

Merged
FlyOverCoderKY merged 3 commits into
mainfrom
grok/scheduler-phase-3
Jul 31, 2026
Merged

FlyOverCoderKY merged 3 commits into
mainfrom
grok/scheduler-phase-3

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

Summary

Implements Phase 3 of docs/PROJECT_PLAN.md: @pegma/scheduler-cloudflare.

  • Explicit host-supplied cron route map → runScheduled
  • controller.scheduledTime → trusted scheduledFor
  • waitUntil registration on the execution context
  • Fail-closed unmapped cron and malformed inputs
  • Real local D1 tests via Cloudflare Workers Vitest pool
  • Docs for Wrangler --test-scheduled, /__scheduled, persist, Docker 30s driver

Phase 3 exit criteria

  • Implement @pegma/scheduler-cloudflare
  • Dispatch ScheduledController.cron through explicit typed route map
  • Prove scheduledTime and waitUntil behavior
  • Document Wrangler local/Docker story
  • Test against real local D1 (restart, repeated events, overlap, checkpoint cycle)

Test evidence

npm run format:check  # pass
npm run check         # pass
npm test              # 35 node + 4 D1 tests pass

Residual risks

  • D1 suite uses Workers Vitest pool (real D1 binding), not a full wrangler dev process-kill e2e; Docker volume persistence is documented for hosts.
  • Package remains unpublished (0.0.0); Phase 4 is consumer integration.

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.
Copilot AI review requested due to automatic review settings July 31, 2026 19:42
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

CI on Node 22 failed because the lockfile omitted a workers-types version
required by the Vitest Workers pool dependency tree.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-cloudflare package with explicit cron→task routing and optional waitUntil wiring.
  • 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.

Comment thread package.json Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread vitest.d1.config.ts Resolved
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

Catch out-of-range Date conversions with a clear TypeError, and align the
Workers pool compatibility date with the locked workerd binary.
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@FlyOverCoderKY
FlyOverCoderKY merged commit cf5841d into main Jul 31, 2026
2 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the grok/scheduler-phase-3 branch July 31, 2026 19:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +191 to +194
const result = await options.scheduler.runScheduled(taskId, {
scheduledFor,
invocationId: newInvocationId(),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

2 participants