Run the tested demo
This repository includes a complete demo: submit six independent addition jobs, run them through a Worker, and record each total as structured result data. The demo uses simple addition to show the same workflow used for inference, evaluation, or other ML jobs. Start more Workers to process Tasks concurrently.
Submit the Tasks
The submission script creates one Task for each pair of numbers and labels all of them for the same Python implementation:
from __future__ import annotations
import labtasker
CASES = (
(1, 2),
(2, 3),
(3, 5),
(5, 8),
(8, 13),
(13, 21),
)
ROUTE = "addition-python"
def main() -> None:
for left, right in CASES:
task = labtasker.submit_task(
{"left": left, "right": right},
name=f"add-{left}-{right}",
routes=[ROUTE],
)
print(f"submitted task_id={task.id} expression={left}+{right}")
if __name__ == "__main__":
main()
Run the Worker
The Worker takes one Task at a time, computes its result, reports it, and asks for another:
from __future__ import annotations
import time
import labtasker
@labtasker.loop(route="addition-python", idle_timeout=0)
def add(
left: int = labtasker.TaskArg(),
right: int = labtasker.TaskArg(),
) -> None:
time.sleep(0.1) # Stand in for inference, evaluation, or another expensive job.
total = left + right
labtasker.finish({"total": total})
print(f"completed expression={left}+{right} total={total}")
if __name__ == "__main__":
add()
Run the complete workflow from the repository root:
cd demo/basic
uv run python submit.py
uv run python worker.py
uv run labtasker task list --status succeeded
uv run labtasker-server stop
On POSIX systems this needs no configuration: the first submission starts the
local Server for demo/basic. To use several Workers, run worker.py in several
terminals after submission. Each process claims the next available Task instead
of requiring you to split the six cases manually.
The
tests/e2e/test_demo.py
end-to-end test runs these exact two files against a real local Server and
verifies all six recorded results.