Core Concepts Overview¶
This section covers the runtime primitives for defining, scheduling, executing, and testing background tasks in litestar-queues.
-
Defining & Enqueuing Tasks
Register async and sync task functions with
@task, discover task modules, and enqueue single or batch workloads throughQueueService. -
Task Options & Uniqueness
Configure priority, delayed starts, expiration deadlines, runtime timeouts, sync thread-pool offloading, and terminal or forever deduplication keys.
-
Task Results & Waiting
Inspect live task state with
TaskResulthandles, refresh records from storage, and await terminal completion across push or polling backends. -
Failures, Retries & Cancellation
Configure exponential
RetryBackoff, raise terminalnon_retryable()orjob_cancelled()exits, and cancel queued or running tasks cooperatively. -
Recurring Schedules
Declare fixed-interval and five-field cron schedules directly on
@task, synchronize schedule records at startup, and preserve retry budgets across restarts. -
Workers & Execution Lifecycle
Choose between
server,asgi, andexternalworker placements, tune per-queue concurrency and adaptive polling, and configure heartbeats and stale recovery. -
Task Dependency Injection
Inject attempt-scoped async context managers via
task_dependency_provideror stateless keyword mappings viatask_dependency_resolver. -
Post-Response Background Tasks
Compare in-handler
await queue_service.enqueue(...)durability with post-responseQueuedBackgroundTaskexecution. -
:material-Sliders:{ .lg .middle } Plugin & Service Configuration
Wire
QueueConfig,WorkerConfig,QueueMaintenanceConfig,QueueEventsConfig, andObservabilityConfigintoQueuePlugin. -
Runtime Namespace Customization
Customize DI state keys, ASGI lifespan names, and OpenTelemetry logger/tracer names with
QueueNamespace. -
Testing Tasks & Workers
Test task callables directly, run full enqueue lifecycles inline with
execution_backend="immediate", and test single-claim execution withconsume_one.