Skip to content

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.

Serverless Scale-to-Zero Dual-Lane Dispatch QueueConfig routes interactive tasks (<= 30m) to CloudTasksExecutionConfig push webhooks and heavy batch tasks to CloudRunExecutionConfig one-shot Job containers. Multi-Backend Router QueueConfig execution_backend = CloudTasks execution_backends = (CloudRun,) @task(execution_backend="cloudrun") schedules_on_enqueue=True Fast Push Lane (<= 30 min) CloudTasksExecutionBackend Dispatches OIDC-signed HTTP POST Schedule Horizon up to 30 days ahead Heavy Batch Lane (Multi-Hour) CloudRunExecutionBackend Calls JobsClient.run_job(overrides) Injects QUEUES_TASK_ID env var Cloud Run Service Webhook /_litestar-queues/cloud-tasks CloudTasksOIDCGuard + claim_task Active lease -> 503; stale -> reclaim Cloud Run Job Execution litestar queues run-task Dedicated CPU/RAM container Exits 0 on complete, 1 on retry/fail
Six-Phase QueueMaintenanceService Sweep Ordered execution of expire, external, stale, schedules, terminal, and events phases via /_litestar-queues/maintenance or litestar queues run-maintenance. 1. expire Expire queued tasks past expires_at expire_pending 2. external Reconcile Cloud Run / Tasks refs reconcile_task 3. stale Reclaim stale running leases & redispatch requeue_stale 4. schedules Claim due cron/interval & enqueue claim_due 5. terminal Delete old terminal rows past retention cleanup_tasks 6. events Prune expired QueueEventLog history rows cleanup_events

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=...).

docs/examples/execution/multi_backend_routing.py
"""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.

    Cloud Tasks Guide

  • Google Cloud Run Jobs


    Isolated one-shot container executions for heavy batch and ML tasks with named hardware profiles and direct enqueue dispatch.

    Cloud Run Jobs Guide

  • Broker Transports


    Shared ID-only dispatch architecture and consumer lifecycle for Google Cloud Pub/Sub, Amazon SQS, RabbitMQ 4.3+, and Apache Kafka.

    Broker Transports Guide

  • Bounded Queue Maintenance


    Run finite 6-phase repair and retention passes via CLI, Kubernetes CronJobs, or authenticated HTTP endpoints.

    Maintenance Guide

  • CLI Operations


    Operational runbook for litestar queues run, run-consumer, run-task, run-maintenance, status, and scheduler-health.

    CLI Operations Guide