{
  "id": "cron",
  "name": "Cron Heartbeat",
  "category": "data",
  "description": "Scheduled background tasks via the per-app CronRoom DO",
  "details": "Reference implementation of a working cron job. Registers a 1-minute 'heartbeat' task in src/cron.ts (consumed by AppCronRoom at construction time). Each fire is logged to the DO's cron_history table; /cron-log subscribes via useCronMonitor and renders live history. Useful both as a working example and as the basis for the cron e2e spec.",
  "files": [
    {
      "src": "src/CronLogPage.tsx",
      "dest": "src/pages/cron-log.tsx"
    }
  ],
  "route": {
    "path": "/cron-log",
    "protected": false
  },
  "code": [
    {
      "file": "src/cron.ts",
      "marker": "export const tasks: CronTask[] = []",
      "insert": "tasks.push({ name: 'heartbeat', intervalMinutes: 1 })"
    }
  ],
  "instructions": [
    "Deploy the app: npm run deploy",
    "Within ~90s, visit /cron-log on the deployed app — you should see one new row per minute as the AppCronRoom alarm fires the heartbeat task.",
    "Open the page on a desktop browser and inspect /ws/cron/<SCOPE_ID>, where SCOPE_ID is app:<APP_ID> from src/constants.ts; APP_ID is immutable, while APP_NAME is only the mutable URL label."
  ],
  "patterns": [
    "Task config lives in code (src/cron.ts), not JSON. AppCronRoom validates at construction time.",
    "Per-app CronRoom DO shards work; no global KV bottleneck. CPU is correctly attributed to the app owner via the tail-worker.",
    "Heartbeat tasks (intervalMinutes: 1) are useful as low-cost liveness probes for cron infrastructure."
  ]
}
