pub struct ClientBuilder { /* private fields */ }Expand description
Builder for the Awa worker client.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
pub fn new(pool: PgPool) -> Self
Sourcepub fn queue(self, name: impl Into<String>, config: QueueConfig) -> Self
pub fn queue(self, name: impl Into<String>, config: QueueConfig) -> Self
Add a queue with its configuration.
Sourcepub fn register<T, F, Fut>(self, handler: F) -> Self
pub fn register<T, F, Fut>(self, handler: F) -> Self
Register a typed worker.
The worker handles jobs of type T where T: JobArgs + DeserializeOwned.
The handler function receives the deserialized args and job context.
Sourcepub fn on_event<T, F, Fut>(self, handler: F) -> Self
pub fn on_event<T, F, Fut>(self, handler: F) -> Self
Register a typed lifecycle event handler for a job kind.
Handlers run only after the corresponding DB state transition commits. They are best-effort in-process hooks, not a durable workflow mechanism. Capture any shared dependencies you need in the closure environment.
Sourcepub fn on_event_kind<F, Fut>(self, kind: impl Into<String>, handler: F) -> Self
pub fn on_event_kind<F, Fut>(self, kind: impl Into<String>, handler: F) -> Self
Register an untyped lifecycle event handler for a specific job kind.
Use this with register_worker(...) or for cross-cutting logic that
doesn’t need typed args.
Sourcepub fn register_worker(self, worker: impl Worker + 'static) -> Self
pub fn register_worker(self, worker: impl Worker + 'static) -> Self
Register a raw worker implementation.
Sourcepub fn state<T: Any + Send + Sync + Clone>(self, value: T) -> Self
pub fn state<T: Any + Send + Sync + Clone>(self, value: T) -> Self
Add shared state accessible via ctx.extract::<T>().
Sourcepub fn heartbeat_interval(self, interval: Duration) -> Self
pub fn heartbeat_interval(self, interval: Duration) -> Self
Set the heartbeat interval (default: 30s).
Sourcepub fn promote_interval(self, interval: Duration) -> Self
pub fn promote_interval(self, interval: Duration) -> Self
Set the scheduled/retryable promotion interval (default: 250ms).
Sourcepub fn heartbeat_rescue_interval(self, interval: Duration) -> Self
pub fn heartbeat_rescue_interval(self, interval: Duration) -> Self
Set the stale-heartbeat rescue interval (default: 30s).
Sourcepub fn deadline_rescue_interval(self, interval: Duration) -> Self
pub fn deadline_rescue_interval(self, interval: Duration) -> Self
Set the deadline rescue interval (default: 30s).
Sourcepub fn callback_rescue_interval(self, interval: Duration) -> Self
pub fn callback_rescue_interval(self, interval: Duration) -> Self
Set the callback-timeout rescue interval (default: 30s).
Sourcepub fn leader_election_interval(self, interval: Duration) -> Self
pub fn leader_election_interval(self, interval: Duration) -> Self
Set the leader election retry interval (default: 10s).
Controls how often a non-leader instance retries acquiring the maintenance advisory lock. Lower values are useful in tests.
Sourcepub fn leader_check_interval(self, interval: Duration) -> Self
pub fn leader_check_interval(self, interval: Duration) -> Self
Set the leader connection health-check interval (default: 30s).
Sourcepub fn global_max_workers(self, max: u32) -> Self
pub fn global_max_workers(self, max: u32) -> Self
Set a global maximum worker count across all queues (enables weighted mode).
When set, each queue gets min_workers guaranteed permits plus a share
of the remaining overflow capacity based on weight.
Sourcepub fn completed_retention(self, retention: Duration) -> Self
pub fn completed_retention(self, retention: Duration) -> Self
Set retention for completed jobs (default: 24h).
Sourcepub fn failed_retention(self, retention: Duration) -> Self
pub fn failed_retention(self, retention: Duration) -> Self
Set retention for failed/cancelled jobs (default: 72h).
Sourcepub fn cleanup_batch_size(self, batch_size: i64) -> Self
pub fn cleanup_batch_size(self, batch_size: i64) -> Self
Set the maximum number of jobs to delete per cleanup pass (default: 1000).
Sourcepub fn cleanup_interval(self, interval: Duration) -> Self
pub fn cleanup_interval(self, interval: Duration) -> Self
Set the cleanup interval (default: 60s).
Sourcepub fn queue_retention(
self,
queue: impl Into<String>,
policy: RetentionPolicy,
) -> Self
pub fn queue_retention( self, queue: impl Into<String>, policy: RetentionPolicy, ) -> Self
Set a per-queue retention override.
Sourcepub fn runtime_snapshot_interval(self, interval: Duration) -> Self
pub fn runtime_snapshot_interval(self, interval: Duration) -> Self
Set how often runtime observability snapshots are published (default: 10s).
Sourcepub fn periodic(self, job: PeriodicJob) -> Self
pub fn periodic(self, job: PeriodicJob) -> Self
Register a periodic (cron) job schedule.
The schedule is synced to the database by the leader and evaluated every second. When a fire is due, a job is atomically enqueued.
Sourcepub fn build(self) -> Result<Client, BuildError>
pub fn build(self) -> Result<Client, BuildError>
Build the client.
Auto Trait Implementations§
impl Freeze for ClientBuilder
impl !RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl UnsafeUnpin for ClientBuilder
impl !UnwindSafe for ClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more