← All examples

Batch processing

Background jobs with retries

A queue is background work with retries. Put tasks on it from Python or with a POST from any system, each task gets its own container, and failed tasks retry with the policy you set.

CPU or GPU containers; workers stay warm for keep_warm_seconds between tasks.

How it works

  1. 1@queue wraps a function; .put(payload) enqueues from Python, POST /queue/NAME/v1 enqueues from anywhere.
  2. 2The controlplane holds the queue; containers pull from it and stay warm while tasks keep coming.
  3. 3retries=, retry_for=[...] and timeout= define the policy; callback_url= posts each result somewhere when it lands.
  4. 4The dashboard shows the queue depth, every task, its status and logs.

The code

demo/queue/app.py
from levers9 import queue

@queue(cpu=1, memory="1Gi", retries=3, keep_warm_seconds=60)
def process(order_id: str) -> dict:
    ...

process.put(order_id="A-1042")          # from Python
# curl -X POST .../queue/process/v1 -d '{"order_id": "A-1042"}'   from anywhere
run it
cd demo/queue
levers9 deploy app.py:process --name process

Where to go next

Related