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.
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
- Reuse the deployed
async-batchendpoint from the async jobs tutorial (setmax_replicashigh enough for your batch). - The list comprehension submits every job without waiting. The connection is freed after each 202, so N spawns take milliseconds, not N×job-time.
- The autoscaler sees the queue depth and adds replicas (up to
max_replicas) to run the jobs in parallel. - Gather by handle:
h.get()blocks only when you actually need each result.
Concepts used: Async job, Autoscaling, Concurrency, Endpoint