Timers
What this is for
A timer is a scheduled job that invokes a pipeline when it comes due — Spine's recurring/one-off background task primitive. system-cron (invoked every minute by the trigger-scheduler Netlify scheduled function) asks the get_due_timers RPC for due timers and runs each one's pipeline.
Why it exists
schedules
You need recurring execution of a specific action with its own credentials and config.
Why it exists (5-whys):
- Different granularity than
timers: timers are app-declared jobs; schedules bind a registered action to a cron expression with explicit ownership — the 018-generation machinery for "run this operation on this calendar." action_idbinding means the schedule inherits the action's schemas, scopes, machine principal, and retry policy — it reuses the contract instead of re-declaring it.machine_principal_id(resolved byresolve_machine_principalinprincipal.ts, falling back toactions.default_machine_principal_id) gives cron runs a declared identity — no human actor exists, but the writes still need scope and auditability.next_run_at/last_run_aton the row +schedule_executionsper run = the same durable-state pattern as timers/executions — a crashed run is visible, a duplicate is a constraint violation.- Root: recurring platform work must carry its own identity —
schedulesbinds the action registry to calendar time under a machine principal, closing the loop "autonomous execution is always attributable." (confirmed 2026-11-13)
timers
You need recurring work such as score decay, cleanup, or report generation without an external scheduler.
Why it exists (5-whys):
- Work like "follow up in 48h" or "decay score weekly" is bound to this app's data and account context — an external scheduler has to reach back in and loses both.
- Each row is an armed instance:
config.interval_minutes/interval_seconds/run_atdeclares the cadence;next_execution(reconciled in020) is the state;update_timer_after_run(071) advances or stops it atomically — missed/duplicate runs are a data problem, not a clock problem. - Typed rows (
type_id,UNIQUE(app_id, slug)) make timers domain vocabulary — "SLA reminder" vs "score decay" are app-declared kinds. - Interval and one-shot share the table because both are "fire at time T" — the config distinguishes recurring from armed one-shots; one mechanism, two shapes.
- Root: time is a trigger like any other event —
timersmakes "later" a governed, auditable, account-scoped primitive instead of an external dependency. (confirmed 2026-11-13)
schedule-executions
Scheduled actions run outside of user sessions; you need a record of success/failure, input/output, and duration for debugging when a schedule misbehaves.
Companion of schedules — its full reasoning is level 4 of the chain in schedules ## Problem it solves and the schedules article.
Fields and settings
- Name — string. Display name; required (
nameandtimer_typeare the API's required fields). - Type — select:
interval,cron,once. Stored but not read by the scheduler — it labels intent only; see Downstream effects. - App ID — select, optional. Owning app; blank = account-scoped.
- Pipeline ID — select. The pipeline invoked when the timer fires.
get_due_timersskips rows wherepipeline_id IS NULL, so a blank pipeline means the timer never runs. - Active — checkbox. Inactive timers are skipped by
get_due_timers. - Description — string, optional.
- Config (JSON) — the schedule. The rescheduler reads
interval_minutes(canonical, minutes between runs) withinterval_secondsas fallback (seconds ÷ 60, same precedence intimers.tsandupdate_timer_after_run, migration 071). The form seeds{ "schedule": "", "interval_seconds": 3600 }—interval_secondsworks via the fallback;scheduleis not honored. - Metadata (JSON) — optional metadata.
Downstream effects
get_due_timersreturns active timers withpipeline_id IS NOT NULLandnext_execution <= now(). The timers API armsnext_executionautomatically on create/activate whenconfig.interval_minutes(orinterval_seconds) resolves to a positive interval — or passnext_executionexplicitly.update_timer_after_runreschedulesnext_execution = now() + intervalwheninterval_minutes(orinterval_seconds/60) resolves positive; otherwise it setsnext_execution = NULLand the timer becomes one-shot/dead.timer_type,schedule, andrun_atare ignored by the RPC.- Each firing also stamps
last_executionand incrementsexecution_count/success_count/failure_count— the source of the list page's Executions and Success Rate columns. - True cron expressions live on the separate
public.schedulestable (read byget_due_schedules), not ontimers— acron-type timer is a label, not a working cron.
Minimal configuration
{
"name": "Hourly sync",
"timer_type": "interval",
"pipeline_id": "<pipeline uuid>",
"is_active": true,
"config": { "interval_minutes": 60 }
}Full configuration
{
"name": "Nightly-ish rollup",
"timer_type": "interval",
"pipeline_id": "<pipeline uuid>",
"is_active": true,
"config": { "interval_minutes": 1440 },
"metadata": { "owner": "platform", "notes": "fires ~daily once next_execution is seeded" }
}Example
A support app keeps an interval timer with interval_minutes: 360 to re-check stale tickets every six hours, and a second timer whose interval_minutes was left blank to run a one-off backfill — after its first fire, update_timer_after_run writes next_execution = NULL so it never re-fires.
Core files
.framework/functions/timers.ts— API (list/get/create/update/delete; armsnext_executionon create/update/toggle-on when the interval resolves, F-056).framework/functions/system-cron.ts— per-tick driver: callsget_due_timers, runsrunPipelineas atimer:<id>principal, thenupdate_timer_after_run.framework/functions/trigger-scheduler.ts— Netlify scheduled entry point that delegates tosystem-cron.framework/migrations/068_cron_schedule_timer_rpcs.sql— theget_due_timers/update_timer_after_runRPCs.framework/src/pages/admin/TimersPage.tsx/TimerDetailPage.tsx— admin UI- Table:
public.timers(timer_type,pipeline_id,next_execution,execution_countadded by migration 020)
Agent notes
- The list's "Next Execution" column shows
Not scheduledwhennext_executionis NULL — an active timer in that state cannot fire until it is re-armed (edit its interval or toggle it off/on). - A timer with a blank
pipeline_idsaves fine but is filtered out byget_due_timers— always pick the pipeline. - Under
netlify dev, timers arm but never fire. Netlify scheduled functions only run on deployed sites — locally,trigger-scheduleris loaded but never invoked on schedule. Emulate a tick withnetlify functions:invoke trigger-schedulerorcurl -X POST 'localhost:8888/.netlify/functions/trigger-scheduler?api_key=<SCHEDULER_API_KEY>'(query param, not a header — the cron handler reads?api_key=/?scheduler_key=;x-internal-secretalso works). A timer that schedules but never executes locally is an environment limitation, not a defect — unless manual invoke also fails. - Trigger dispatch requires
INTERNAL_INVOKE_SECRETset and a dev-server restart — a queued execution that never runs usually means the secret is missing (see Add a trigger). - The API arms
next_executionautomatically when the interval resolves; for timers created before F-056 (or with unparseable config), setnext_executionin the DB (e.g.now() + interval). After the first successful run, the interval keeps it rescheduling. - "Success Rate" is
success_count / execution_count; failures still reschedule — a broken pipeline does not stop the cadence.