ADR-017: Background Cron Scheduler Over the Generic CRUD Surface¶
Status: Accepted Date: 2026-08
Context¶
The ask: scheduled background actions, user-creatable from Settings, listable/kanban/calendar/graph like any other entity, running arbitrary Go code as a chosen user with a permission check, keeping a downloadable execution history, and pruning that history after a sliding retention window — a one-shot execution date, not a recurring cron-expression field.
Decision¶
Cron/CronHistoryride the generic CRUD surface, unlikechatter/notebook/savedfilter— neither table needs a visibility rule the generic filter chain can't express, so plainorm.Register[cron.Cron]()(noWithExcluded()) gives List and Kanban and Calendar and Graph for free through the existing frontend engine. Two small hand-mounted additions sit on top:POST/PUT /api/v1/cronare overridden to resolveaction_codefrom the registry, andGET /api/v1/cron_history/:id/logstreams a run's log file (its permission still derives automatically from the route).- Cron is one-shot (
ExecutionDate), cleared tonilright after a run so it never re-fires. An action wanting to reschedule itself just sets a newExecutionDateas a side effect of its ownRun— no separate recurrence mechanism. - Actions are Go code registered from a module's own
cron.gofile —internal/cron.Register( Action{...})called frominit(), mirroringmodule.RegisterGoModule's exact shape.Action.Sourceis populated via//go:embed cron.goso the form's read-only "Code" page always shows the real source that runs. ActionIDis not validated against the registry at write time — an unknown id fails exactly like any other run-time problem: a failedCronHistoryrow, visible in the calendar (red) and the run's log.- Run-as-user permission failures surface via the record's own chatter feed — a background scheduler has no live HTTP caller to return an error to, so a missing-permission run posts a
kind: "log"chatter message naming the run-as user, the action, and the missing permission. - Local disk for log files, not S3 — a cron log is small, workspace-internal text;
Config.CronLogDirkeeps the feature available with zero extra infra. - One poll loop does both scheduling and retention —
Scheduler.Runticks every minute, running due crons and callingSweepHistory(a hard delete, since "prune history" means actually gone, not soft-deleted). calendarColorFieldis a small, generic engine addition (a boolean field can tint a Calendar card, e.g. red for a failed run) — not a cron-only hack.
Deliberate cuts: no recurring schedule/cron-expression field, no manual "run now" trigger, no Kanban archived-column auto-hide (the engine has no per-column visibility toggle), ActionID is a plain text field rather than a live dropdown (descriptors are static TypeScript with no route to ask Go what actions exist), and HistoryRetentionYears lives per-row on Cron rather than as a workspace-wide setting (a background job has no "current company").
Consequences¶
- Adding a genuinely recurring schedule later means adding an interval field and teaching the scheduler to compute the next
ExecutionDateinstead of clearing it — additive, no migration. action_idtypos are only caught by the first scheduled run failing, not at creation time.- Cron log files live on local disk, so a multi-instance deployment needs a shared volume for downloads to work from every instance — not a concern for this codebase's current single-instance target.
Reference Implementation¶
core/internal/cron/ (models.go, registry.go, scheduler.go, retention.go, logstore.go), core/modules/cron/ (module.go, handler.go, cron.go), core/cmd/app/main.go (go cronScheduler.Run(ctx)). See Background Cron Scheduler.