awa-worker
Worker runtime for the Awa Postgres-native job queue: dispatch, claim, heartbeat, completion-batching, maintenance, and lifecycle hooks.
Most Rust applications depend on the awa facade and never reach for this crate directly. Use awa-worker when you need the runtime types without the re-export shim — typically when you are building higher-level frameworks or alternate transports on top of Awa.
What's in here
- Client —
ClientandClientBuilderconfigure queues, register handlers, attach lifecycle hooks, and start the runtime.HealthCheck,QueueHealth,QueueCapacity, andTransitionWorkerRoleexpose the observability and transition-aware capabilities. - Job context —
JobContext(with cancellation, structured progress, and callback registration),CallbackToken,CallbackGuard. - Handler results —
JobResult(Completed,RetryAfter,Snooze,Cancel,WaitForCallback) andJobError. Implement theWorkertrait directly or register typed closures withClientBuilder::register. - Queue configuration —
QueueConfig(concurrency, weighted mode, rate limiting, per-claim deadlines),RateLimit. - Lifecycle hooks —
JobEvent<T>andUntypedJobEventfire when handler execution starts and after guarded finalization commits, useful for cache invalidation, notifications, and metrics emission. - HTTP worker —
HttpWorker,HttpWorkerConfig,HttpWorkerModedispatch jobs to serverless endpoints over HTTP with HMAC-BLAKE3 signing. See ADR-018. - Maintenance — the elected maintenance leader runs rescue, promotion, queue/lease/claim ring rotation and prune, DLQ cleanup, descriptor cleanup, cron evaluation, and queue-health publication.
- Metrics —
AwaMetricsexposes the runtime metric surface for Prometheus / OTel scrapers.
Capabilities
- Vacuum-aware queue storage — workers default to the queue-storage engine: append-only ready/terminal partitions, rotating lease and receipt rings, and separate deferred/DLQ tables described in ADR-019 and ADR-023.
- Dead Letter Queue — terminal failures land in
dlq_entriesfor any queue withdlq_enabledset. Per-queue policy is configured throughQueueConfigand thedlq_enabled_by_defaultbuilder setting; seedocs/dead-letter-queue.md. - Descriptor catalog —
ClientBuilder::queue_descriptorandjob_kind_descriptordeclare display name, owner, tags, and docs URL alongside the worker. The runtime syncs these toqueue_descriptors/job_kind_descriptorson start (ADR-022). - Per-claim deadlines —
QueueConfig::deadline_durationwriteslease_claims.deadline_aton claim. Expired claims are force-closed by the rescue path with'deadline_expired'. - Priority aging — applied at claim time on the queue-storage engine (ADR-005).
- Heartbeat + deadline rescue — two independent rescue paths cover crash and runaway failure modes (ADR-003).
Cancellation Semantics
Cancellation in Awa is cooperative.
- Rust handlers can poll
ctx.is_cancelled(). - Python handlers can poll
job.is_cancelled(). - The runtime flips that flag for:
- graceful shutdown
- stale-heartbeat rescue
- deadline rescue
That lets long-running handlers stop work gracefully and return an explicit result like JobResult::Cancel(...), JobResult::RetryAfter(...), or awa.Cancel(...) in Python.
There is an important distinction between:
- handler cancellation signals
- the in-memory cancellation flag becomes
true - the handler can observe cancellation while it is still running
- the in-memory cancellation flag becomes
- admin/job-state cancellation
admin::cancel(...)/client.cancel(...)marks the jobcancelledin storage- pending or waiting jobs transition immediately
- if the exact running attempt is still alive on a worker process, the matching handler also sees its in-memory cancellation flag flip
If a running job is cancelled in storage and the handler keeps running, its later completion/retry/cancel attempt is treated as stale and ignored.
See also
License
MIT OR Apache-2.0