Add a timer
Goal
Create a public.timers row that runs a pipeline every config.interval_minutes via the system cron sweep.
Prerequisites
- The
system_adminrole — timer mutations are second-surface gated (decision0026, migration081); account members read but cannot write. - A pipeline to point at (Add a pipeline) —
get_due_timersignores timers withpipeline_idNULL.
Steps
Create the timer. Admin UI → Configs → Timers → New (
configs/timers/new), orPOST /api/timers?action=create—nameandtimer_typerequired (.framework/functions/timers.ts). Setpipeline_idandconfig.interval_minutes:{ "name": "Hourly sync", "timer_type": "interval", "pipeline_id": "<pipeline-uuid>", "config": { "interval_minutes": 60 } }timer_typeis a label (interval|cron|oncein the admin detail page,.framework/src/pages/admin/TimerDetailPage.tsx) — rescheduling resolvesconfig.interval_minutesfirst, thenconfig.interval_seconds(seconds ÷ 60) (see below).next_executionis armed for you. On create or toggle-on, the API computesnext_executionfromconfig.interval_minutes(orconfig.interval_seconds, seconds ÷ 60);oncetimers arm from an ISOconfig.run_at/config.schedule. You may also passnext_executionexplicitly. Ifnext_executionever ends up NULL on an active timer it cannot fire —get_due_timersrequiresnext_execution IS NOT NULL— so check it first when a timer never runs.Understand the clock.
trigger-scheduleris the Netlify scheduled function (* * * * *innetlify.toml); each minute it invokes thesystem-cronhandler under the system principal, which callsget_due_timers(now()), thenrunPipeline(timer.pipeline_id, …)with atimer:<id>machine principal, thenupdate_timer_after_run(.framework/functions/system-cron.ts).netlify devdoes not run scheduled functions. Clockwork only exists on deployed Netlify — locally,trigger-scheduleris loaded but never invoked on schedule. To emulate a tick, invoke it manually:curl -X POST http://localhost:8888/.netlify/functions/trigger-scheduler \ -H 'x-nf-event: schedule' \ -d "{\"next_run\": \"$(date -u +%Y-%m-%dT%H:%M:%S.000Z)\"}" # or: npx netlify functions:invoke trigger-scheduler- Rescheduling is automatic — or never.
update_timer_after_runstampslast_execution, incrementsexecution_count/success_count/failure_count, and setsnext_execution = now() + <resolved interval>where the interval isconfig.interval_minutes(canonical, minutes) orconfig.interval_seconds(fallback, seconds ÷ 60) — otherwiseNULL, so the timer fires once and stops (.framework/migrations/071_timer_interval_keys.sql— the dual-key resolver; the RPCs themselves are from068).
Verify
SELECT id, next_execution, last_execution, execution_count FROM timersshowsnext_executionin the future, then advancing each tick.- Observability → Executions shows pipeline runs with a
timer:<id>principal. timer.execution_countincrements;success_count/failure_countreflect outcomes.
Common mistakes
interval_secondsvsinterval_minutes.interval_minutes(minutes) is canonical;interval_secondsis a fallback (seconds ÷ 60). A timer saved with onlyinterval_secondsstill reschedules — but setinterval_minutesfor clarity since the admin page may seed either.next_executionis armed but can go NULL. The API sets it on create and re-arms on activation — a timer stuck dormant has usually lostnext_executionto a one-shot completion or a NULL reschedule; check the column first.toggleis blind.?action=toggleflipsis_activeto its negation with no target-state argument — read the row first.- Cron expressions do nothing. There is no cron-expression evaluator;
timer_type: "cron"is only a label — scheduling is interval arithmetic onnext_execution. - Timer with no
pipeline_id— filtered out ofget_due_timers.
Reference
- timers entity page · timers function reference · system-cron reference · trigger-scheduler reference
- Automation — Timers and the scheduler