Jobs Reference

Native path. In-process job queues with drain, retry/dead-letter hooks, and

optional persist/restore.

std.jobs

Function Role
make() Create a queue
enqueue(q, job) Push a job map/value
dequeue(q) Pop one job
drain(q, n) Take up to n jobs
len(q) Queue length
stats(q) / metrics(q) Counters for observability
mark_processed(q, ok) Record success path
mark_failed(q, err) Record failure / dead-letter path
persist(q, path) / restore(q, path) Optional disk hooks
schedule / tick / schedules Delayed work helpers

Minimal drain loop


import std.jobs { make, enqueue, drain, mark_processed, mark_failed, stats }

fn main() {
    let q = make()
    enqueue(q, { "kind" => "ping" })
    enqueue(q, { "kind" => "pong" })

    let batch = drain(q, 4)
    for job in batch {
        if job != null {
            // process job["kind"] here
            mark_processed(q, true)
        } else {
            mark_failed(q, "empty")
        }
    }
    println(stats(q))
}

alef run main.alef

Persist sketch

When your app needs restart survival, call persist after enqueue bursts and

restore on boot. Paths and exact map shapes follow the binary you ship โ€”

verify with a small local program before production.

Agent backend pattern

See AI Agent Backend for the end-to-end recipe.

Related