Execution Transports Overview¶
An execution backend (BaseExecutionBackend) determines how a persisted QueuedTaskRecord is triggered and where the task callable runs. The storage backend (BaseQueueBackend) remains the sole authority for task arguments, status transitions, retry budgets, and fenced heartbeats across all execution transports.
Execution Transport Comparison Matrix¶
| Execution Backend | Config / Selector | Dispatch Mechanism | Scale-to-Zero | Typical Task Duration | Execution Consumer Surface | Remote Provider Cancellation |
|---|---|---|---|---|---|---|
Local Worker ("local") |
"local" (default) |
Worker claims due records from storage | No (long-lived worker) | Seconds to hours | Worker (server, asgi, or litestar queues run) |
Worker-control wakeup + durability poll |
Immediate ("immediate") |
"immediate" |
Executed inline inside QueueService.enqueue() |
N/A (in-process) | Milliseconds (testing) | Inline caller coroutine | Coroutine cancellation |
Google Cloud Tasks ("cloudtasks") |
CloudTasksExecutionConfig |
schedules_on_enqueue=True (HTTP push delivery) |
Yes (--min-instances 0) |
Up to 30 minutes (1800s max deadline) |
POST /_litestar-queues/cloud-tasks |
Yes (delete_task) |
Google Cloud Run Jobs ("cloudrun") |
CloudRunExecutionConfig |
schedules_on_enqueue=True (default) or worker dispatcher |
Yes (ephemeral job container) | Minutes to 24 hours | litestar queues run-task (python -m litestar_queues.consumer) |
Yes (cancel_execution) |
Google Cloud Pub/Sub ("pubsub") |
PubSubExecutionConfig |
Worker dispatcher publishes ID-only message | Consumer pool autoscaling | Up to 10m ack window (extended automatically) | litestar queues run-consumer --backend pubsub |
Storage-fenced claim check + control wakeup |
Amazon SQS ("sqs") |
SqsExecutionConfig |
Worker dispatcher publishes ID-only message | Consumer pool autoscaling | Up to 12h visibility window (extended automatically) | litestar queues run-consumer --backend sqs |
Storage-fenced claim check + control wakeup |
RabbitMQ 4.3+ ("rabbitmq") |
RabbitMQExecutionConfig |
Worker dispatcher publishes ID-only message to quorum queue | Consumer pool autoscaling | Configurable consumer timeout | litestar queues run-consumer --backend rabbitmq |
Storage-fenced claim check + control wakeup |
Apache Kafka ("kafka") |
KafkaExecutionConfig |
Worker dispatcher publishes ID-only message to topic | Consumer group scaling | Unbounded (manual offset commit after attempt) | litestar queues run-consumer --backend kafka |
Storage-fenced claim check + control wakeup |
Multi-Backend Execution Routing¶
A single QueueConfig can register multiple execution backends via execution_backends alongside the default execution_backend. Individual tasks select their transport via @task(..., execution_backend=..., execution_profile=...), or callers override it per invocation at enqueue(..., execution_backend=..., execution_profile=...).
"""Routing tasks across multiple execution backends with QueueConfig.execution_backends."""
from litestar_queues import QueueConfig, WorkerConfig, task
from litestar_queues.backends.redis import RedisBackendConfig
from litestar_queues.execution.cloudrun import CloudRunExecutionConfig
from litestar_queues.execution.cloudtasks import CloudTasksExecutionConfig
@task("webhooks.deliver_event", queue="webhooks", execution_backend="cloudtasks")
async def deliver_event(event_id: str) -> str:
"""Deliver a short-lived webhook via Google Cloud Tasks."""
return f"delivered:{event_id}"
@task("ml.backfill_embeddings", queue="batch", execution_backend="cloudrun", execution_profile="gpu-batch")
async def backfill_embeddings(dataset_id: str) -> str:
"""Execute a long-running batch job via Google Cloud Run Jobs."""
return f"backfilled:{dataset_id}"
def build_hybrid_execution_config() -> QueueConfig:
"""Register both Cloud Tasks and Cloud Run Jobs alongside a default execution backend."""
cloud_tasks = CloudTasksExecutionConfig(
project_id="my-gcp-project",
location="us-central1",
queue_id="webhooks-queue",
service_url="https://api-worker-uc.a.run.app",
service_account_email="tasks-invoker@my-gcp-project.iam.gserviceaccount.com",
trust_platform_auth=True,
verify_oidc=True,
)
cloud_run = CloudRunExecutionConfig(
project_id="my-gcp-project",
region="us-central1",
job_name="queue-worker-default",
profiles={"gpu-batch": "queue-worker-gpu"},
schedules_on_enqueue=True,
)
return QueueConfig(
queue_backend=RedisBackendConfig(url="redis://redis.internal:6379/0"),
execution_backend=cloud_tasks,
execution_backends=(cloud_tasks, cloud_run),
worker=WorkerConfig(placement="external"),
)
async def main() -> None:
"""Verify multi-backend registration and resolution."""
config = build_hybrid_execution_config()
resolved = config.resolved_execution_backends()
assert set(resolved) == {"cloudtasks", "cloudrun"}
assert deliver_event.execution_backend == "cloudtasks"
assert backfill_embeddings.execution_backend == "cloudrun"
assert backfill_embeddings.execution_profile == "gpu-batch"
Guides in This Section¶
-
:material-cloud-Sync:{ .lg .middle } Google Cloud Tasks
Scale-to-zero HTTP push execution with OIDC token verification, 30-day native scheduling horizons, and inline stale recovery.
-
Google Cloud Run Jobs
Isolated one-shot container executions for heavy batch and ML tasks with named hardware profiles and direct enqueue dispatch.
-
Broker Transports
Shared ID-only dispatch architecture and consumer lifecycle for Google Cloud Pub/Sub, Amazon SQS, RabbitMQ 4.3+, and Apache Kafka.
-
Bounded Queue Maintenance
Run finite 6-phase repair and retention passes via CLI, Kubernetes CronJobs, or authenticated HTTP endpoints.
-
CLI Operations
Operational runbook for
litestar queues run,run-consumer,run-task,run-maintenance,status, andscheduler-health.