Skip to content

0015 Start the daily run from a Cloudflare Cron Trigger

  • Status: Accepted
  • Date: 2026-12-06

Context

The daily run in .github/workflows/collect.yml starts from GitHub's schedule trigger. GitHub starts scheduled runs when it has capacity, so they can be late, and a run can be dropped. On three days in a row, the scheduled run was late or missing:

Day Planned Started
2026-12-04 10:37 UTC 14:46 UTC, about 4 hours late
2026-12-05 10:37 UTC 18:55 UTC, about 8 hours late
2026-12-06 10:37 UTC Not started by 14:38 UTC

The first schedule, at 06:17 UTC, also ran over two hours late. Moving to minute 37 didn't help.

A late run costs more than a late email:

  • Testers get their picks in the evening, or not at all.
  • The workaround, starting a daily run by hand after 16:00 UTC (The daily collection didn't run on time), depends on the maintainer being there.
  • If the late scheduled run still comes after a run started by hand, it reads Himalayas and Remote OK a second time that day, which their terms don't allow (Job sources). On 2026-12-05 it also failed on the email's idempotency key, fixed in pull request #39.

Options

Stay on GitHub's schedule

  • For: nothing to build, host, or pay for, and no new secret.
  • Against: the start time stays out of WFHeaven's control. The maintainer has to watch for missing runs, and a run started by hand can still meet a late scheduled run.

A Cloudflare Cron Trigger that calls GitHub's dispatch API

A small Worker with a Cron Trigger at 10:37 UTC calls GitHub's API to start the workflow, as the Run workflow button does: POST /repos/hajdigergely/WFHeaven/actions/workflows/collect.yml/dispatches with {"ref": "main", "inputs": {"mode": "daily"}}.

  • For: Cloudflare runs Cron Triggers on time, and a workflow_dispatch run usually starts within minutes. WFHeaven already runs on Cloudflare (ADR 0011), and Cron Triggers are part of the Workers Free plan. The workflow itself doesn't change.
  • Against: one more moving part, and a GitHub token stored as a Worker secret. The token is a fine-grained token for this repository only, with Actions: read and write. It expires and has to be renewed. If the Worker or the token breaks, no run starts at all, unless the workflow keeps a fallback.

Decision

Start the daily run from a Cloudflare Cron Trigger, and stop relying on GitHub's schedule.

  1. A separate, small Worker, not the demo's Worker, so the GitHub token is never in the Worker that faces the public. It has no routes: only a scheduled() handler that calls the dispatch API, and logs the HTTP status, never the token. It retries once after a GitHub server error or a network error, and never after any other answer.
  2. A once-a-day guard in the workflow. A first job checks, with the workflow's own GITHUB_TOKEN, whether any run today already started its Collect jobs step, even one that failed later. If one did, the run stops before reading any job source. This protects the source rules whatever starts the run: the Cron Trigger, a retry, a re-run, or a click. A test email never reaches that step, so it doesn't count. If GitHub's API can't be read, the guard fails and nothing runs.
  3. GitHub's schedule stays as a late fallback, at 15:37 UTC. With the guard, it does nothing on a day the Cron Trigger worked, and starts the run on a day it didn't.
  4. The maintainer creates the token and sets it with wrangler secret put. Claude never sees it.

Consequences

  • The run starts at about 10:37 UTC every day. The kb article The daily collection didn't run on time is archived; The daily run didn't start replaces it.
  • Any run that reached Collect jobs blocks every other daily run that day, even if it failed later. A day whose run failed after collecting gets no second try: the source rules matter more than one day's email. Picks of an unsent email aren't remembered, so the next day's run sends them. (Changed on 2026-12-06, before the first run with the guard: at first, only a run that succeeded counted.)
  • Himalayas and Remote OK are read at most once a day, even with two triggers, because of the guard.
  • A new token to renew. Its expiry date goes in the roadmap, and an expired token shows as a failed dispatch in the Worker's logs, with GitHub's schedule still starting a late run.
  • To measure after the change: the start time of the next seven runs. If GitHub's dispatch is also slow, revisit this decision.
  • Built in trigger/ and daily/once_a_day.py (Daily trigger).