timers
What it does
CRUD plus toggle over public.timers — the config rows that bind a pipeline_id to a schedule (timer_type + config, with next_execution/execution_count bookkeeping columns). This function never executes anything: firing is done by system-cron, which polls the get_due_timers RPC each tick and calls runPipeline as a timer:<id> machine principal, then reschedules via update_timer_after_run (.framework/migrations/068_cron_schedule_timer_rpcs.sql).
Route and methods
/.netlify/functions/timers, reachable as /api/timers (/api/* → /.netlify/functions/:splat, .framework/public/_redirects). Dispatch is by ?action= only — the HTTP method is ignored:
| Call | Handler |
|---|---|
/api/timers?action=list | list |
/api/timers?action=get&id=<uuid> | get |
/api/timers?action=create | create |
/api/timers?action=update (id in body or query) | update |
/api/timers?action=remove (id in body or query) | remove |
/api/timers?action=toggle (id in body or query) | toggle |
A bare GET /api/timers with no action throws Unsupported action: undefined. Conversely GET ?action=create reaches create (with a null body → required-field error).
Authentication
Standard createHandler auth: x-api-key → machine principal, x-internal-secret → internal principal, Bearer <jwt> → human; anonymous → 401.
list/createrequirectx.accountId;create/update/remove/toggleadditionally require a person+account context.- Mutations are second-surface gated (
canAccessConfigObject, decision0026):create/update/remove/togglerequiresystem_admin— everyone else getsInsufficient permissions to … timers. RLS agrees: migration081splitstimers_accessinto an account-scopedtimers_readplus a system-admintimers_write, so direct PostgREST matches the API. - Reads are sanitized: non-admins get
{ id }per row (timer rows carry nodesign_schema).
Request contract
list (query): app_id, timer_type, is_active ('true'/'false'). Ordered by name; no pagination parameters.
get (query): id.
create (body): name, timer_type required. Optional: app_id, description, config {}, pipeline_id, metadata {}, is_active, next_execution (explicit value wins over the computed arming). account_id and created_by stamped from context. (Columns timer_type, pipeline_id, next_execution, execution_count were added by .framework/migrations/020_schema_reconciliation.sql.)
update (id in body or query + body): allowlist — name, description, config, pipeline_id, metadata, is_active, timer_type, app_id, next_execution.
remove (id in body or query): hard delete.
toggle (id in body or query): flips is_active to its negation — no target-state argument.
Response contract
Standard { data, error, meta } envelope. list/get/create/ update/toggle → sanitized row(s); remove → { success: true }.
Side effects
toggleandupdatestampupdated_at;is_activeis whatget_due_timersgates on (plusnext_execution <= now).emitLogwritestimer.created/.updated/.deleted/.toggledaudit rows topublic.logs.next_executionis armed here:createcomputes it fromconfig.interval_minutes(orinterval_secondsfallback) when the row will be active;update/togglerecompute it whenconfigoris_activechange without an explicitnext_execution. After firing,update_timer_after_runreschedules (recurring) or nulls it (one-shot/exhausted).
Errors
| Condition | HTTP | Message |
|---|---|---|
| No account context (list, create) | 500 | Account context required |
| Missing create fields | 500 | name and timer_type are required |
| No person+account context | 500 | User context (person and account) required |
| Non-admin on any mutation | 500 | Insufficient permissions to create/update/delete/toggle timers |
Missing id | 500 | Timer ID is required |
| Missing row (remove/toggle) | 500 | Timer not found |
| Missing/unknown action | 500 | Unsupported action: <action> |
Agent notes
next_executionis a real column (migration 020) and IS in the create/update allowlists — pass it explicitly to override the computed arm time.get_due_timersreads it;update_timer_after_runadvances it onsystem-cronticks.toggleflips blindly — read the row first if you need a target state; concurrent toggles can cancel each other.removeis a hard delete (unliketriggers, which soft-deletes).- Distinct roles:
timers= config CRUD;system-cron= firing;pipelines= what runs;pipeline-executions= run records. See Automation.