Skip to main content

Worker

Struct Worker 

Source
pub struct Worker<Adapter, Handler> { /* private fields */ }
Expand description

Runtime-neutral consumer loop over one Queue topic.

The worker owns the retry ceiling, the exponential backoff, and the dead-letter route; the adapter only has to honour the visibility delay passed to Queue::nack. It never spawns a thread or reads a clock, so it runs unchanged on any executor.

Implementations§

Source§

impl<Adapter, Handler> Worker<Adapter, Handler>

Source

pub fn new(queue: Adapter, topic: impl Into<String>, handler: Handler) -> Self

Creates a worker that consumes topic with handler.

Source

pub const fn with_retry(self, retry: RetryPolicy) -> Self

Replaces the retry policy.

Source

pub fn with_dead_letter(self, dead_letter: DeadLetter) -> Self

Replaces the dead-letter destination.

Source

pub const fn with_idle_backoff(self, idle_backoff: Duration) -> Self

Sets how long Worker::run waits after an empty poll.

Source

pub fn topic(&self) -> &str

Returns the consumed topic.

Source§

impl<Adapter, Handler, HandlerFuture> Worker<Adapter, Handler>
where Adapter: Queue, Handler: Fn(Delivery) -> HandlerFuture + Send + Sync, HandlerFuture: Future<Output = Result<(), JobError>> + Send,

Source

pub async fn step(&self) -> Result<WorkerStep, QueueError>

Runs one receive, dispatch, and settle cycle.

§Errors

Returns the adapter failure raised by receive, ack, nack, or the dead-letter publish. A handler failure is not an error: it is settled by the retry policy and reported in the WorkerStep.

Source

pub async fn run<Sleep, SleepFuture>( &self, sleep: Sleep, ) -> Result<(), QueueError>
where Sleep: Fn(Duration) -> SleepFuture, SleepFuture: Future<Output = ()>,

Runs cycles until the adapter fails, awaiting sleep on an empty poll.

The caller owns the loop’s lifetime and its timer: race this future against a shutdown signal from its own runtime.

§Errors

Returns the first adapter failure raised by a cycle.

Auto Trait Implementations§

§

impl<Adapter, Handler> Freeze for Worker<Adapter, Handler>
where Adapter: Freeze, Handler: Freeze,

§

impl<Adapter, Handler> RefUnwindSafe for Worker<Adapter, Handler>
where Adapter: RefUnwindSafe, Handler: RefUnwindSafe,

§

impl<Adapter, Handler> Send for Worker<Adapter, Handler>
where Adapter: Send, Handler: Send,

§

impl<Adapter, Handler> Sync for Worker<Adapter, Handler>
where Adapter: Sync, Handler: Sync,

§

impl<Adapter, Handler> Unpin for Worker<Adapter, Handler>
where Adapter: Unpin, Handler: Unpin,

§

impl<Adapter, Handler> UnsafeUnpin for Worker<Adapter, Handler>
where Adapter: UnsafeUnpin, Handler: UnsafeUnpin,

§

impl<Adapter, Handler> UnwindSafe for Worker<Adapter, Handler>
where Adapter: UnwindSafe, Handler: UnwindSafe,

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, 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, 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.