Skip to main content

Module tasks

Module tasks 

Source
Expand description

schedules + tasks_runs + tasks_logs — the agents tasks {schedule, list, run} storage tier.

Per-schedule payload: an argv vector to invoke on each scheduled poll, the minimum interval between invocations in seconds, and a JSON snapshot of the caller’s AgentArguments so the runner can re-install identity env vars at fire-time.

Schedule rows are NEVER deleted. Versions are separate rows (-- overwrite inserts version = max+1, shadowing the older rows); run history is one tasks_runs row per firing (written atomically by claim_pending’s claim query); each item a fired task emits is one tasks_logs row linked to its run.

Structs§

ListedSchedule
One row from schedules as surfaced by agents tasks list. command is decoded from its JSON-string column.
RunRow
Subset of a schedule row that agents tasks run needs to fire one task, plus the id of the tasks_runs row the claim minted for this firing (the log writer links every emitted item to it).

Functions§

claim_pending
Atomically claim every pending schedule in parent’s subtree (its own AIH or any descendant): ONE statement both selects the eligible rows and inserts their tasks_runs rows, so each returned RunRow carries the freshly-minted run_id. Schedules are never updated or deleted by a run — exhaustion is purely “has a run” (oneshots) / “newest run too recent” (recurring), and only the newest version of each (name, aih) is eligible.
insert_schedule
Insert one schedule row and return its (id, version).
insert_task_log
Append one emitted item to a run’s log. value is the serialized tasks::run::ResponseItem exactly as it crossed the wire.
list_schedules
List schedules matching the supplied filters. Only the newest version of each (name, aih) is visible; readiness derives from each row’s newest tasks_runs entry. Every filter is optional and composes additively — the SQL is one statement that gates each predicate on whether the corresponding bind is active (0 = inactive bool flag, NULL = unset after_id/count).