Skip to content

fix(core): tick the piggyback cron scheduler from the middleware request path - #1423

Closed
swissky wants to merge 1 commit into
emdash-cms:mainfrom
swissky:fix/piggyback-cron-tick
Closed

fix(core): tick the piggyback cron scheduler from the middleware request path#1423
swissky wants to merge 1 commit into
emdash-cms:mainfrom
swissky:fix/piggyback-cron-tick

Conversation

@swissky

@swissky swissky commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

On Cloudflare Workers the middleware selects the PiggybackScheduler, whose contract is "call this from middleware on each request" — but runtime.tickCron() had no call sites, so plugin cron tasks never executed on Workers (overdue tasks sat at status = idle forever; details and field evidence in #1422).

This adds the tick to both request branches of the middleware:

  • the anonymous fast path (right after the runtime is initialized for page hooks), and
  • the full runtime path (admin/API/authenticated traffic).

PiggybackScheduler.onRequest() debounces internally (60s) and runs fire-and-forget via Promise.allSettled, so requests gain no latency. On Node the scheduler is the NodeCronScheduler, for which tickCron() is a type-guarded no-op.

Tests: new middleware-cron-tick.test.ts (modeled on middleware-prerender.test.ts) pins one tick per request on both paths — red before the fix, green after. The existing prerender test's MOCK_RUNTIME gained the tickCron member to match the runtime interface.

Closes #1422

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (packages/core)
  • pnpm lint passes (lint:quick clean)
  • pnpm test passes (targeted: tests/unit/astro/middleware-*.test.ts — 13/13 green; tests/unit/astro/vite-config.test.ts fails 8/8 on my machine on unmodified main too — environmental, untouched by this PR)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (n/a — no UI strings)
  • I have added a changeset (emdash patch)
  • New features link to an approved Discussion (n/a — bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Cursor + Fable 5 (reviewed and verified by a human before submission)

Screenshots / test output

❯ vitest run tests/unit/astro/middleware-cron-tick.test.ts   # before fix
  × ticks the cron system on anonymous public page requests  (expected 1 call, got 0)

❯ vitest run tests/unit/astro/middleware-cron-tick.test.ts tests/unit/astro/middleware-prerender.test.ts   # after fix
  Test Files  2 passed (2)
       Tests  13 passed (13)

…est path

PiggybackScheduler was instantiated on Cloudflare Workers but
runtime.tickCron() had no call sites, so plugin cron tasks never
executed. Tick once per request on both the anonymous fast path and
the full runtime path; the scheduler debounces internally.

Closes emdash-cms#1422
@changeset-bot

changeset-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3c881f9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ascorbic

Copy link
Copy Markdown
Collaborator

Thanks. This was already fixed in #1312, which was merged today

@ascorbic ascorbic closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin cron never fires on Cloudflare Workers — PiggybackScheduler is instantiated but tickCron() has no call sites

2 participants