Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
48 changes: 44 additions & 4 deletions specs/epics/cron-starter/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`) |
4 changes: 2 additions & 2 deletions specs/epics/cron-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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 |
| Upstream | [vercel/examples `solutions/cron`](https://github.com/vercel/examples/tree/main/solutions/cron) |
| 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

Expand Down
2 changes: 1 addition & 1 deletion specs/epics/cron-starter/epic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/<interval> to record the newest Hacker News story and the run time in Vercel KV, and a page that polls /api/data/<interval> 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:
Expand Down
8 changes: 4 additions & 4 deletions specs/epics/cron-starter/implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Milestones land in order; each task is one pull request on an
`orun/CR-n-<slug>` 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`.

**Done when**
- 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,
Expand All @@ -22,15 +22,15 @@ 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.

**Done when**
- `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`.
Expand Down
Loading