Docs › Cloudflare Workers Cron Triggers with RunVouch

Cloudflare Workers Cron Triggers with RunVouch

A Worker's scheduled() handler has no output you can look at later, no exit code and, on the free plan, a CPU time limit that ends a run mid-way without an error you will see.

How it runs on Cloudflare Workers Cron Triggers

Inside scheduled(event, env, ctx), with two fetch() calls to the API. Workers cannot run a binary.

Store the key

wrangler secret put RUNVOUCH_KEY; read it as env.RUNVOUCH_KEY.

Report the run (two HTTP calls)

export default {
  async scheduled(event, env, ctx) {
    const h = {"X-API-Key": env.RUNVOUCH_KEY, "content-type": "application/json"};
    const {run_id} = await (await fetch("https://api.runvouch.com/v1/runs/start", {method: "POST", headers: h,
      body: JSON.stringify({agent: "nightly-report", source: "cloudflare"})})).json();
    let status = "ok", evidence = {};
    try { evidence = {rows: await doTheWork(env)}; } catch (e) { status = "fail"; }
    ctx.waitUntil(fetch("https://api.runvouch.com/v1/runs/end", {method: "POST", headers: h,
      body: JSON.stringify({run_id, status, evidence})}));
  }
}
// wrangler.toml:  [triggers]  crons = ["0 2 * * *"]

The start call returns run_id; the end call takes status (ok or fail), optional cost and tokens, and evidence as a JSON object of booleans. Full reference on the API page.

Register the cadence and caps

rv agent nightly-report --cadence 24h --grace 30m --max-runtime 1h --evidence --cap-run-cost 2

Register the agent once, from anywhere with the key. Cadence is what turns a schedule that stopped into an alert; --evidence makes a run without evidence a failure; the caps pause the agent when it overspends.

What goes silent on Cloudflare Workers Cron Triggers

What RunVouch detects

AlertWhat it means here
MISSEDcadence plus grace passed and no run started
FAILEDnon-zero exit or a reported failure, with the stderr excerpt
NO_EVIDENCEthe run said ok but the file, URL or assertion you required is missing
STALLEDa run started and never ended within max runtime
RETRY_STORMthe same tool called with identical input many times in one run
BUDGET_RUN / BUDGET_DAYcost cap crossed; the agent is paused until you resume it
DRIFTduration or output size far off its 7-run baseline

Need a key? Get a free key · Stuck? contact