Conduit.Worker
Conduit.Worker — task-based worker pool with heartbeat and stale-rescue.
Each worker runs as an independent March task in an infinite loop:
- fetch_next — claim one job from the queue (SELECT … FOR UPDATE SKIP LOCKED).
- mark_running — atomically record the worker_id and increment attempt.
- heartbeat task — spawned in parallel; updates heartbeat_at periodically so
the stale-rescue loop can detect crashed workers.
4. rate-limit check — if configured, try to acquire a token; snooze on failure.
5. dispatch — call the registered performer function.
6. handle_result — transition the job to completed | retry | discard | dlq | snooze.The heartbeat task is stopped via a Vault flag (not task_await_unwrap, which would block forever on the infinite heartbeat loop).
start_workers/4 also spawns one stale-rescue loop per queue group that reclaims jobs abandoned by workers that died mid-execution.
Functions
fnstart_workersstart_workers(storage : s, queue : String, count : Int, poll_interval_ms : Int) : List(Task(()))#
Start count worker tasks for the given queue, plus one stale-rescue task.
Each worker runs an infinite poll loop: fetch → mark_running → heartbeat →
dispatch → handle_result → repeat. The stale-rescue task fires every
`poll_interval_ms * 10` ms, finding jobs whose heartbeat has expired and
resetting them to pending for re-execution.
Returns all task handles. In production, wrap these in a supervisor for
auto-restart on unexpected panics.