Configuration
An app is configured entirely through the Ardiq(...) constructor:
from ardiq import Ardiq
app = Ardiq( redis_url="redis://localhost:6379", queue_name="emails", priorities=["low", "default", "high"], concurrency=32, result_ttl_ms=600_000,)Options
Section titled “Options”| Option | Default | Description |
|---|---|---|
redis_url | redis://localhost:6379 | Redis connection URL. |
queue_name | "default" | Logical queue — namespaces all Redis keys for this app. |
priorities | ["default"] | Priority lane names, lowest-first. Higher lanes drain first. |
default_priority | the middle lane | Where a task with no priority goes. Must be one of priorities. |
weights | None | Lane name to weight. Lanes share pickups by weight instead of draining highest-first. |
limits | None | Lane name to the most tasks a worker holds from it at once. Lanes left out are limited only by concurrency. |
concurrency | 16 | Max tasks running at once in a worker. |
prefetch | concurrency * 2, or concurrency with several lanes | Max tasks held in memory; drives backpressure against Redis. |
idle_timeout_ms | 60000 | When an unrenewed in-flight task may be reclaimed by another worker. |
result_ttl_ms | 300000 | How long results live. 0 drops results immediately; a negative value keeps them forever. |
burst | False | Exit once the queue drains (also settable via app.burst or the CLI --burst). |
serializer | msgpack | Callable[[Any], bytes] used to encode arguments and results. |
deserializer | msgpack | Callable[[bytes], Any] used to decode them. |
cron_poll_s | 1.0 | Seconds between re-checks of each @app.cron’s next fire time. |
Notes on specific options
Section titled “Notes on specific options”queue_name
Section titled “queue_name”Each app/worker pair operates on one logical queue. Workers sharing a queue_name form a
Redis consumer group and split the work between them. Use distinct names to isolate
unrelated workloads on the same Redis instance.
priorities
Section titled “priorities”The list is lowest-priority first. With ["low", "default", "high"], a worker drains
high before default before low. A task’s lane comes from its
@task(priority=...) default or a per-call
.options(priority=...) override.
Any priority naming a lane outside this list raises a ValueError — see
Priorities.
weights
Section titled “weights”By default lanes drain strictly: while high has work, low waits, however long that
takes. weights makes the lanes share the worker instead:
app = Ardiq( priorities=["low", "default", "high"], weights={"low": 5, "default": 15, "high": 80},)While every lane has work, 80 of each 100 tasks a worker picks up come from high, 15
from default and 5 from low, interleaved rather than in runs. A lane with nothing
waiting hands its share to the others, highest first, so weights never leave a worker
idle while work is queued. Tasks reclaimed from a dead worker still go first.
Every lane needs a positive integer weight; a missing, unknown or non-positive entry raises
a ValueError. app.weights reads them back, lowest lane first.
limits
Section titled “limits”concurrency caps a worker as a whole. limits caps one lane within it, so a heavy task
can run one at a time while light tasks keep running beside it:
app = Ardiq( priorities=["heavy", "default"], concurrency=4, limits={"heavy": 1},)
@app.task(priority="heavy")def process_scene(scene_id: str) -> dict: ... # ~1 GB of RAM: two at once would not fitA worker holds at most one heavy task at a time, running or prefetched, and the other
three slots go to default. Give heavy tasks a lane of their own with priority=, and the
limit covers every task in it.
A lane at its limit is not read at all, so the tasks waiting in it stay in Redis for any
worker with room, and they never sit in this worker’s memory ahead of the lane’s limit.
The limit is per worker process, like concurrency: with ardiq run --workers 2, each
process holds up to its own limit.
A lane left out has no limit beyond concurrency. An unknown lane or a limit below 1
raises a ValueError. app.limits reads them back, lowest lane first.
concurrency and prefetch
Section titled “concurrency and prefetch”concurrency caps how many tasks execute simultaneously. prefetch caps how many are
pulled into memory ahead of execution; a larger prefetch smooths bursts but holds more work
off Redis. With a single lane the default is prefetch = concurrency * 2.
With several lanes the default is prefetch = concurrency. A prefetched task waits in
memory in the order it was read, so a task that reaches a higher lane later would queue
behind it. With prefetch equal to concurrency the worker reads only when a slot frees
up, so the lane order (or the weights) decides what runs next. A larger prefetch
brings the delay back: a higher-lane task can wait for up to prefetch - concurrency
lower-lane tasks on top of the ones already running. Raise it only when keeping every slot
busy matters more than the order.
idle_timeout_ms
Section titled “idle_timeout_ms”A running task periodically renews its claim via a heartbeat. If a worker dies, its
in-flight tasks stop renewing; after idle_timeout_ms another worker reclaims them
(XAUTOCLAIM). Lower it for faster recovery, raise it if tasks legitimately run long
without renewing.
result_ttl_ms
Section titled “result_ttl_ms”Controls result retention:
- positive — keep results this many ms (default 5 minutes).
0— don’t store results at all.- negative — keep results forever (you manage cleanup yourself).
serializer / deserializer
Section titled “serializer / deserializer”See Serialization. Every process on a queue must use the same codec.
cron_poll_s
Section titled “cron_poll_s”How often a running worker re-stages each recurring task’s next
occurrence. The default of 1s is fine for minute-resolution cron; lower it only if you rely
on short every= intervals.
Made bytay.dev