Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

The Awa worker client — manages dispatchers, heartbeat, and maintenance.

Implementations§

Source§

impl Client

Source

pub fn builder(pool: PgPool) -> ClientBuilder

Create a new builder.

Source

pub async fn start(&self) -> Result<(), AwaError>

Start the worker runtime. Spawns dispatchers, heartbeat, and maintenance.

Source

pub async fn shutdown(&self, timeout: Duration)

Graceful shutdown with drain timeout.

Phased lifecycle:

  1. Stop dispatchers (no new jobs claimed)
  2. Signal in-flight jobs to cancel
  3. Wait for dispatchers to exit
  4. Drain in-flight jobs (heartbeat + maintenance still alive!)
  5. Stop heartbeat + maintenance
Source

pub fn pool(&self) -> &PgPool

Get the pool reference.

Source

pub async fn resolve_callback( &self, callback_id: Uuid, payload: Option<Value>, default_action: DefaultAction, run_lease: Option<i64>, ) -> Result<ResolveOutcome, AwaError>

Resolve a pending external callback and dispatch the matching lifecycle event + ADR-029 follow-up specs.

The callback transition (Complete / Fail) and any registered on_completed_enqueue / on_exhausted_enqueue follow-up INSERTs commit in a single transaction. A follow-up INSERT failure (or a panic in the user-supplied closure) rolls the callback transition back; the caller sees an Err and can surface a retryable failure to the external sender so the callback can be redelivered. Ignored produces no transition; Resumed does not currently fire a follow-up spec because resume re-enters execution and the executor emits the eventual outcome event itself.

Prefer this over awa_model::admin::resolve_callback when you want Completed/Exhausted hooks or follow-up enqueues to fire for callback-driven outcomes. Hooks fire only in this process and only after the transaction commits.

Source

pub async fn complete_external( &self, callback_id: Uuid, payload: Option<Value>, run_lease: Option<i64>, ) -> Result<JobRow, AwaError>

Complete a waiting job via its callback. The callback completion and any registered on_completed_enqueue follow-up INSERTs commit atomically. A spec INSERT failure rolls the completion back and returns Err so the external sender can retry. The in-process Completed hook fires after the transaction commits.

Source

pub async fn fail_external( &self, callback_id: Uuid, error: &str, run_lease: Option<i64>, ) -> Result<JobRow, AwaError>

Fail a waiting job via its callback. The callback failure and any registered on_exhausted_enqueue follow-up INSERTs commit atomically. A spec INSERT failure rolls the failure back and returns Err so the external sender can retry. The in-process Exhausted hook fires after the transaction commits.

Source

pub async fn retry_external( &self, callback_id: Uuid, run_lease: Option<i64>, ) -> Result<JobRow, AwaError>

Requeue a waiting job via its callback. The callback retry and any registered on_retried_enqueue follow-up INSERTs commit atomically. A spec INSERT failure rolls the retry back and returns Err so the external sender can retry. The in-process Retried hook fires after the transaction commits.

admin::retry_external_in_tx resets attempt to 0 as part of requeuing the job from scratch, so the returned JobRow no longer reflects the attempt that was being retried. The pre-retry attempt number is captured under the same row lock before the transition runs so the Retried event and spec context report the failed-attempt number — matching the inline Retried semantics where attempt is “the attempt that was retried”, not the post-transition value.

Source

pub async fn health_check(&self) -> HealthCheck

Health check.

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more