Developer docs / AI Fabric tutorials

Fan out hundreds of async jobs, gather the results

  • Async job
  • Web endpoint

Take it for a spin

The whole program in one file, ready to run.

app.py
import bladekit

app = bladekit.app("async-batch", image="fabric/base")   # same crunch endpoint

@app.local_entrypoint()
def main():
    crunch = bladekit.Function.from_name("async-batch", "/crunch")

    # Each spawn() returns after the 202, so submit the whole batch fast.
    handles = [crunch.spawn({"n": i}) for i in (2, 3, 4, 5)]
    print("submitted", len(handles), "jobs")

    # Collect results by handle (they ran concurrently across replicas).
    for h in handles:
        print(h.call_id, "->", h.get(timeout=60))

Run it

  1. Reuse the deployed async-batch endpoint from the async jobs tutorial (set max_replicas high enough for your batch).
  2. The list comprehension submits every job without waiting. The connection is freed after each 202, so N spawns take milliseconds, not N×job-time.
  3. The autoscaler sees the queue depth and adds replicas (up to max_replicas) to run the jobs in parallel.
  4. Gather by handle: h.get() blocks only when you actually need each result.

Concepts used: Async job, Autoscaling, Concurrency, Endpoint

Contact the team

Loading the form…