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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ writes.

## Status

Phase 2 is implemented in source. The repository contains the
`@pegma/scheduler` contracts, validated task registry, durable runner
(`createScheduler`), Memory Store and Azurite adversarial tests, and design
documentation. No package has been published.
Phase 3 is implemented in source. The repository contains
`@pegma/scheduler` (contracts, durable runner), `@pegma/scheduler-cloudflare`
(explicit Cron Trigger dispatch), Memory Store / Azurite / local D1 tests, and
design documentation. No package has been published.

The first consumers are:

Expand All @@ -23,12 +23,10 @@ The first consumers are:

## Packages

| Package | Status | Responsibility |
| ----------------------------- | --------------- | ------------------------------------------- |
| `@pegma/scheduler` | Phase 2 source | Contracts, durable task state, and runner |
| `@pegma/scheduler-cloudflare` | Planned Phase 3 | Thin explicit Cron Trigger dispatch adapter |

Do not create the Cloudflare package directory until its implementation starts.
| Package | Status | Responsibility |
| ----------------------------- | -------------- | ------------------------------------------- |
| `@pegma/scheduler` | Phase 3 source | Contracts, durable task state, and runner |
| `@pegma/scheduler-cloudflare` | Phase 3 source | Thin explicit Cron Trigger dispatch adapter |

## Development

Expand All @@ -37,6 +35,9 @@ npm ci
npm run format:check
npm run check
npm test
# or separately:
npm run test:node
npm run test:d1
```

See [docs/PROJECT_PLAN.md](docs/PROJECT_PLAN.md) for the delivery sequence.
8 changes: 4 additions & 4 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ and business-safe storage transitions.
`@pegma/scheduler` is runtime-neutral and takes an injected Storage Core
`Store`, Spine `Clock`, and Spine `Logger` through `createScheduler`.

`@pegma/scheduler-cloudflare` is deferred until Phase 3. It will translate a
Cloudflare `ScheduledController` into the core invocation contract and route
`controller.cron` through an explicit host-supplied map. It will not own D1,
Wrangler configuration, or task discovery.
`@pegma/scheduler-cloudflare` translates a Cloudflare `ScheduledController`
into the core invocation contract and routes `controller.cron` through an
explicit host-supplied map. It does not own D1, Wrangler configuration, or
task discovery.

Azure begins as a tested composition example. A package is justified only
after repeated adapter behavior appears in a second Azure consumer.
Expand Down
48 changes: 36 additions & 12 deletions docs/CLOUDFLARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@ Cloudflare owns Cron Trigger delivery and the host owns `wrangler.jsonc`.
Production cron expressions have five fields and one-minute resolution. A
30-second production cadence is therefore outside Cloudflare Cron Triggers.

The planned adapter receives a `ScheduledController` and dispatches its `cron`
value through a static host map. Multiple tasks may intentionally share one
cron expression; each retains independent durable state.
`@pegma/scheduler-cloudflare` receives a `ScheduledController` and dispatches
its `cron` value through a static host map. Multiple tasks may intentionally
share one cron expression; each retains independent durable state.

```ts
const routes = {
"* * * * *": ["health.probe-targets"],
"*/10 * * * *": ["github.sync-orgs"],
} as const;
import { createCloudflareSchedulerDispatch } from "@pegma/scheduler-cloudflare";

const dispatch = createCloudflareSchedulerDispatch({
scheduler,
routes: {
"* * * * *": ["health.probe-targets"],
"*/10 * * * *": ["github.sync-orgs"],
},
});

export default {
async scheduled(controller, env, ctx) {
// waitUntil is registered inside the adapter when ctx is passed.
await dispatch.scheduled(controller, ctx);
},
};
```

The same expression must appear in Wrangler configuration. The adapter does
not mutate deployment configuration or discover it.
not mutate deployment configuration or discover it. Unmapped cron values fail
closed.

`controller.scheduledTime` (Unix milliseconds) becomes the trusted
`scheduledFor` ISO timestamp for durable occurrence suppression.

## Local Docker

Expand All @@ -44,10 +60,18 @@ survive restarts. Do not treat Memory Store as durability evidence.

## Test layers

1. Core tests invoke tasks directly against Memory Store.
2. Adapter tests construct scheduled controller inputs without a network.
3. Wrangler integration tests call `/__scheduled` against local D1.
4. A green Ops Hub fixture proves Docker volume and repeated trigger behavior.
1. Core tests invoke tasks directly against Memory Store (and Azurite).
2. Adapter unit tests construct scheduled controller inputs without a network.
3. Cloudflare Vitest pool tests run against real local D1
(`packages/scheduler-cloudflare/src/fixture.d1.test.ts`).
4. A green Ops Hub fixture (Phase 4) proves Docker volume and repeated trigger
behavior.

Run the D1 suite alone:

```sh
npm run test:d1
```

References:

Expand Down
8 changes: 4 additions & 4 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Status

**Stage:** Phase 0 requirements validation, Phase 1 repository foundation, and
Phase 2 durable runner are complete in source. No package is published or
production-usable.
**Stage:** Phases 0–3 are complete in source (contracts, durable runner, and
Cloudflare Cron Trigger adapter with local D1 tests). No package is published
or production-usable.

**Trigger:** Ops Hub and Support Desk independently need the same explicit,
durable coordination boundary for recurring work.
Expand Down Expand Up @@ -79,7 +79,7 @@ registrations and state fail closed, and the full local gate passes.
**Exit criterion:** concurrency, crash, replay, stale-worker, and checkpoint
tests pass against Memory Store and Azurite.

### Phase 3 — Cloudflare adapter and local story
### Phase 3 — Cloudflare adapter and local story (complete)

- Implement `@pegma/scheduler-cloudflare` only when work begins.
- Dispatch `ScheduledController.cron` through an explicit typed route map.
Expand Down
19 changes: 18 additions & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,28 @@ checkpoint cycle, occurrence suppression, and concurrent claim fencing on a
real Table Storage protocol endpoint. Vitest starts Azurite via
`test/azurite.ts` for the full suite.

## Phase 3 Cloudflare adapter coverage

Adapter unit tests cover:

- cron route dispatch and multi-task routes;
- `scheduledTime` → `scheduledFor` conversion;
- `waitUntil` registration;
- unmapped cron fail-closed behavior;
- overlap suppression and checkpoint cycles through the adapter.

Real local D1 tests (`npm run test:d1`) through
`@pegma/storage-cloudflare-d1` and the Cloudflare Workers Vitest pool cover:

- a complete checkpoint cycle with occurrence suppression;
- durable state surviving a re-composed “restart”;
- concurrent claim fencing on the same task;
- `waitUntil` wiring on the execution context.

## Adapter and consumer matrix

Before publication, also run:

- real local Cloudflare D1 through Wrangler (Phase 3);
- an Ops Hub health and GitHub-sync fixture (Phase 4);
- Support Desk mail-send, reconciliation, terminal sweep, queue repair, and
inactive-sweep fixtures (Phase 4).
Expand Down
Loading