diff --git a/README.md b/README.md index 8c87c4e..605a0f3 100644 --- a/README.md +++ b/README.md @@ -112,4 +112,5 @@ build on every push and pull request. `ci.yml` is the Orun pipeline: set KV root, renders the Worker's config with the real namespace id, and deploys to `stage`, then `prod` — the triggers register with the Worker and start firing on the next minute. Cloudflare caps Cron Triggers per account by -plan; seven per environment is the template's count. +plan (5 on Workers Free, 250 on Workers Paid); seven per environment is the +template's count, so stage + prod need the Paid plan. diff --git a/specs/epics/README.md b/specs/epics/README.md index 7261c6f..cd199e0 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`cron-starter/`](./cron-starter/) | **CR** | Draft | Vercel's Cron Jobs example, equivalent in code and function, on Cloudflare Workers with Cron Triggers driving the same API routes and Workers KV holding the timestamps | +| [`cron-starter/`](./cron-starter/) | **CR** | ✅ Shipped | Vercel's Cron Jobs example, equivalent in code and function, on Cloudflare Workers with Cron Triggers driving the same API routes and Workers KV holding the timestamps | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/cron-starter/IMPLEMENTATION-STATUS.md b/specs/epics/cron-starter/IMPLEMENTATION-STATUS.md index 9e17bd3..b853aef 100644 --- a/specs/epics/cron-starter/IMPLEMENTATION-STATUS.md +++ b/specs/epics/cron-starter/IMPLEMENTATION-STATUS.md @@ -5,10 +5,10 @@ the code departed from `design.md` or from the upstream template. | Milestone | State | PR | |---|---|---| -| CR0 — the spec | | | -| CR1 — the crons on Workers | | | -| CR2 — the KV namespace from Terraform | | | -| CR3 — ready to instantiate | | | +| CR0 — the spec | ✅ Shipped | [#1](https://github.com/sourceplane/cron-starter/pull/1) | +| CR1 — the crons on Workers | ✅ Shipped | [#2](https://github.com/sourceplane/cron-starter/pull/2) | +| CR2 — the KV namespace from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/cron-starter/pull/3) | +| CR3 — ready to instantiate | ✅ Shipped | [#4](https://github.com/sourceplane/cron-starter/pull/4) | ## Departures from the upstream template @@ -95,3 +95,43 @@ Next `^16.0.10` → `16.3.8`; React 19; Tailwind `^3.2.7` (resolves 3.4); and fixture. Upstream's `turbo.json`, `pnpm-lock.yaml`, `vercel.json`, `.gitignore` and `.env.example` are not carried; `apps/web/README.md` is upstream's, verbatim. + +## Verified + +- Local: `pnpm run wire:fixture`, `pnpm typecheck`, `pnpm lint` (0 errors, + 1 upstream warning), `pnpm test` (16 tests: the cron table equals the + template's `triggers.crons`; the scheduled handler for all seven + expressions, an unknown one and a non-2xx; `lib/kv.ts` over a mocked + namespace; both routes with mocked KV and a mocked Hacker News), + `pnpm build` (`/` static, `/api/cron/[cron]` and `/api/data/[interval]` + dynamic, Worker + assets, `populateCache local`) green; `tsc` stays green + after the build (the generated bundle is excluded). +- `wrangler dev --port 8808 --config wrangler.jsonc --test-scheduled` over + the built Worker with a local namespace: `/` 200 ("Cron Triggers on + Cloudflare", no beacon without a token); `/api/data/1m` → `{}` before any + run; `GET /__scheduled?cron=*+*+*+*+*` → "Ran scheduled event" with the + Worker logging `/api/cron/1m 200 "OK"`; `/api/data/1m` then → + `{"fetchedAt":…,"id":…,"title":…}`; `0 0 1 * *` → `1mo` likewise; an + unknown expression → a warning and no call; `/api/cron/10m` by hand → + `"OK"`; `/nope` 404; `/thumbnail.png` and `/favicon.ico` 200. +- `wrangler deploy --dry-run` on the rendered config bundles `worker.ts` + (4.5 MiB, the seven triggers and the `KV`/`ASSETS` bindings accepted). +- `terraform init -backend=false && terraform validate` green on + `infra/terraform/cloudflare-kv`. +- CI: `Checks` green on #1, #2, #3 and #4. +- Not verified: the KV apply and a live deploy — both need the product + linked to an Orun workspace with a Cloudflare connection (`ORUN_CI`) — + and a trigger firing on the wall clock, which only a deployed Worker does + (the account needs Workers Paid for fourteen triggers across stage and + prod; Free allows five). + +## Versions + +| Package | Version | Why | +|---|---|---| +| next | 16.3.8 | newest inside `@opennextjs/cloudflare` 1.20.11's peer range (16.4.x fails at boot on the adapter) | +| @opennextjs/cloudflare | ^1.20.11 | `getCloudflareContext` for the binding; the generated fetch handler the custom entry wraps; static-assets cache + `populateCache local` | +| wrangler | ^4.151.0 | `triggers.crons`, `--test-scheduled`, compatibility_date 2026-10-01 | +| @vercel/examples-ui | ^1.0.5 | upstream's pin; React 19 pairing as upstream's lockfile | +| swr, ms | ^2.1.0, ^2.1.3 | upstream's pins | +| eslint-config-next | 16.3.8 | flat config for Next 16 (upstream: eslint 8 + `canary`) | diff --git a/specs/epics/cron-starter/README.md b/specs/epics/cron-starter/README.md index 38bde04..051f942 100644 --- a/specs/epics/cron-starter/README.md +++ b/specs/epics/cron-starter/README.md @@ -8,7 +8,7 @@ The port keeps the template's pages, API routes, component, styles and `@vercel/ | Field | Value | |-------|-------| -| Status | Draft | +| Status | ✅ Shipped — CR0–CR3 landed (#1–#4); KV apply and live deploy gated on a linked workspace | | Cluster | **CR** (CR0–CR3) | | Owner(s) | `apps/web` (the page, the routes, the worker entry) · `tests/web` · `infra/terraform/cloudflare-kv` | | Builds on | `cirrus-baseline` conventions: the `cloudflare-kv` root and the `@@wiring(...)@@` deploy-time render; `kv-redis-starter`'s shape for a KV-bound Next app | @@ -16,7 +16,7 @@ The port keeps the template's pages, API routes, component, styles and `@vercel/ | Changes | What runs the routes on schedule (Vercel Cron → Cron Triggers through a custom worker entry), where they write (Vercel KV → Workers KV behind `lib/kv.ts`), analytics (beacon), the Workers build, tests, the KV root and the deploy contract; page copy says Cron Triggers and Workers KV | | Decisions locked | (1) One Worker: the triggers sit on the Next Worker and the scheduled handler calls the OpenNext fetch handler in-process with a synthetic request — not a second Worker calling the routes over HTTP. (2) The routes stay as written: `lib/kv.ts` mirrors `kv.set`/`kv.get` (JSON values, `"OK"` from `set`). (3) `wrangler.jsonc` is rendered per environment from the wiring document; never committed. (4) The seven schedules are the template's, verbatim, in `triggers.crons` and in `lib/crons.ts`; a test holds the two together. | | Gate | CR1 is the first user-visible rung. CR2 applies only with a linked workspace; it is verified by `terraform validate`. | -| Shipped as | | +| Shipped as | `main` after [#4](https://github.com/sourceplane/cron-starter/pull/4); verified locally under `wrangler dev --test-scheduled` with a local namespace | ## Read order diff --git a/specs/epics/cron-starter/epic.yaml b/specs/epics/cron-starter/epic.yaml index f5efd86..90272ec 100644 --- a/specs/epics/cron-starter/epic.yaml +++ b/specs/epics/cron-starter/epic.yaml @@ -9,7 +9,7 @@ metadata: spec: title: "Vercel's Cron Jobs example on Cloudflare Workers with Cron Triggers and Workers KV" summary: "Vercel's Cron Jobs example — seven cron schedules, each requesting /api/cron/ to record the newest Hacker News story and the run time in Vercel KV, and a page that polls /api/data/ for them — runs on Cloudflare Workers + Static Assets through @opennextjs/cloudflare. The seven schedules are Cron Triggers on the same Worker: a custom worker entry re-exports the generated fetch handler and adds a scheduled handler that turns the expression that fired back into the request Vercel used to make, so the template's own route runs on schedule. The timestamps live in a Workers KV namespace provisioned by Terraform through Orun and bound through the Cirrus baseline's wiring documents." - state: backlog + state: completed milestones: - name: "CR0 — the spec" exitCriteria: diff --git a/specs/epics/cron-starter/implementation-plan.md b/specs/epics/cron-starter/implementation-plan.md index a553080..07b2250 100644 --- a/specs/epics/cron-starter/implementation-plan.md +++ b/specs/epics/cron-starter/implementation-plan.md @@ -3,7 +3,7 @@ Milestones land in order; each task is one pull request on an `orun/CR-n-` branch with an `Orun-Task: CR-n` trailer. -## CR0 — the spec +## CR0 — the spec ✅ This doc set, `epic.yaml` and the task contracts, merged to `main`. @@ -11,7 +11,7 @@ This doc set, `epic.yaml` and the task contracts, merged to `main`. - the five documents and `epic.yaml` are on `main` - `tasks/CR-1..CR-4.TaskContract.yaml` exist -## CR1 — the crons on Workers +## CR1 — the crons on Workers ✅ `apps/web` with the routes over `lib/kv.ts`, the custom worker entry and the scheduled handler, the wrangler template (triggers + the KV token) + fixture, @@ -22,7 +22,7 @@ scheduled handler, the wrangler template (triggers + the KV token) + fixture, - `wrangler dev --test-scheduled` answers `/` with "Cron Triggers on Cloudflare", `/api/data/1m` with `{}` before any run, `GET /__scheduled?cron=*+*+*+*+*` runs `/api/cron/1m`, and `/api/data/1m` then carries `fetchedAt`; `/nope` is a 404 - the tests cover the cron→interval table (and that it equals `triggers.crons`), the scheduled handler's request, `lib/kv.ts` over a mocked namespace, and both routes with mocked KV and Hacker News — no network -## CR2 — the KV namespace from Terraform +## CR2 — the KV namespace from Terraform ✅ `infra/terraform/cloudflare-kv` (component + terraform), validated. @@ -30,7 +30,7 @@ scheduled handler, the wrangler template (triggers + the KV token) + fixture, - `terraform validate` passes on the root - the wiring keys the root outputs (`app_kv_id`) are the ones the template's token names -## CR3 — ready to instantiate +## CR3 — ready to instantiate ✅ README (run, test, preview, fire a trigger, deploy; the schedules table), `IMPLEMENTATION-STATUS.md`, epic `completed`.