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>
impl<Adapter, Handler> Worker<Adapter, Handler>
Sourcepub fn new(queue: Adapter, topic: impl Into<String>, handler: Handler) -> Self
pub fn new(queue: Adapter, topic: impl Into<String>, handler: Handler) -> Self
Creates a worker that consumes topic with handler.
Sourcepub const fn with_retry(self, retry: RetryPolicy) -> Self
pub const fn with_retry(self, retry: RetryPolicy) -> Self
Replaces the retry policy.
Sourcepub fn with_dead_letter(self, dead_letter: DeadLetter) -> Self
pub fn with_dead_letter(self, dead_letter: DeadLetter) -> Self
Replaces the dead-letter destination.
Sourcepub const fn with_idle_backoff(self, idle_backoff: Duration) -> Self
pub const fn with_idle_backoff(self, idle_backoff: Duration) -> Self
Sets how long Worker::run waits after an empty poll.
Source§impl<Adapter, Handler, HandlerFuture> Worker<Adapter, Handler>
impl<Adapter, Handler, HandlerFuture> Worker<Adapter, Handler>
Sourcepub async fn step(&self) -> Result<WorkerStep, QueueError>
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.
Sourcepub async fn run<Sleep, SleepFuture>(
&self,
sleep: Sleep,
) -> Result<(), QueueError>
pub async fn run<Sleep, SleepFuture>( &self, sleep: Sleep, ) -> Result<(), QueueError>
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.