beam-logo
Task Queues

Offload long-running, GPU-heavy functions to a managed queue. Enqueue tasks from an API or directly in Python, process them sequentially or concurrently, and retrieve results whenever you’re ready — with automatic retries built in.

app.py
from beam import task_queue, Output


# Run resource-intensive functions asynchronously
@task_queue(cpu=1.0, memory=128, gpu="A10G")
def handler():
    result = 839 * 18

    # Save the result to a file
    file_name = "result.txt"
    with open(file_name, "w") as f:
        f.write(f"The result is: {result}")

    # Upload the output to retrieve later
    Output(path=file_name).save()


# Enqueue a task from anywhere
handler.put()
Capabilities

A managed queue for long-running work.

Offload heavy functions to the cloud, process them sequentially or concurrently, and retrieve results whenever you need them.

How it works

From a Python function to a running queue.

01

Define a task queue

Add the @task_queue decorator to any function and configure CPU, memory, GPU, and your image in one place.

02

Enqueue tasks

POST to the deployed API or call .put() in Python. Requests return a Task ID immediately so nothing blocks while work runs.

03

Retrieve your results

Get a webhook fired to your callback_url the moment a task finishes, or poll the /task API for outputs and queue stats.

app.py
from beam import task_queue, Image


# 1. Decorate any function as a task queue
@task_queue(
    cpu=1.0,
    memory=128,
    gpu="T4",
    image=Image(python_packages=["torch"]),
)
def multiply(x):
    return {"result": x * 2}


# 2. Enqueue a task — returns instantly
multiply.put(x=10)
# => Enqueued task: f0d205da-e74b-47ba...

# 3. Retrieve the result via webhook or the /task API
FAQ

Frequently asked questions.

What is a task queue?

A task queue lets you deploy resource-intensive functions on Beam. Instead of processing tasks immediately, you add them to a queue and process them later — either sequentially or concurrently — without blocking the caller.

When should I use a task queue instead of an endpoint?

Endpoints are RESTful APIs designed for synchronous tasks that complete in 180 seconds or less. For longer-running or GPU-heavy jobs, use an async task_queue so requests return immediately and the work runs in the background.

How do I create one?

Add the @task_queue decorator to any function and configure cpu, memory, gpu, and your image. You can then enqueue tasks over the deployed API or directly in Python with .put().

How do I get the result of a task?

Because task queues are async, the API returns a Task ID. Retrieve results either by adding a callback_url so Beam fires a webhook when the task completes, or by polling the /task API, where your saved Outputs appear in the outputs list.

What happens if a task fails?

Task Queues include a built-in retry system. If a task fails for any reason, such as an out-of-memory error or an application exception, it's retried three times before automatically moving to a failed state.

Can I queue tasks without exposing an endpoint?

Yes. Call the .put() method directly in Python to insert tasks into the queue programmatically — useful for triggering work from scripts or other services without deploying an API.

Ship an app on infra you won’t outgrow

Get started with $30 of free credit, refreshed every month.