Browse documentation

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:

CallHandler
/api/timers?action=listlist
/api/timers?action=get&id=<uuid>get
/api/timers?action=createcreate
/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/create require ctx.accountId; create/update/remove/ toggle additionally require a person+account context.
  • Mutations are second-surface gated (canAccessConfigObject, decision 0026): create/update/remove/toggle require system_admin — everyone else gets Insufficient permissions to … timers. RLS agrees: migration 081 splits timers_access into an account-scoped timers_read plus a system-admin timers_write, so direct PostgREST matches the API.
  • Reads are sanitized: non-admins get { id } per row (timer rows carry no design_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

  • toggle and update stamp updated_at; is_active is what get_due_timers gates on (plus next_execution <= now).
  • emitLog writes timer.created / .updated / .deleted / .toggled audit rows to public.logs.
  • next_execution is armed here: create computes it from config.interval_minutes (or interval_seconds fallback) when the row will be active; update/toggle recompute it when config or is_active change without an explicit next_execution. After firing, update_timer_after_run reschedules (recurring) or nulls it (one-shot/exhausted).

Errors

ConditionHTTPMessage
No account context (list, create)500Account context required
Missing create fields500name and timer_type are required
No person+account context500User context (person and account) required
Non-admin on any mutation500Insufficient permissions to create/update/delete/toggle timers
Missing id500Timer ID is required
Missing row (remove/toggle)500Timer not found
Missing/unknown action500Unsupported action: <action>

Agent notes

  • next_execution is a real column (migration 020) and IS in the create/update allowlists — pass it explicitly to override the computed arm time. get_due_timers reads it; update_timer_after_run advances it on system-cron ticks.
  • toggle flips blindly — read the row first if you need a target state; concurrent toggles can cancel each other.
  • remove is a hard delete (unlike triggers, which soft-deletes).
  • Distinct roles: timers = config CRUD; system-cron = firing; pipelines = what runs; pipeline-executions = run records. See Automation.

Framework documentation — Verified November 17, 2026 · source revision 761dfb9.

Was this page helpful? Ask a question · Report a documentation problem