pub struct Worker { /* private fields */ }Expand description
Polls a queue and executes registered handlers with bounded concurrency.
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn new(queue: &Queue) -> Self
pub fn new(queue: &Queue) -> Self
Creates a worker with 16 concurrent slots and five-minute leases.
Sourcepub fn poll_interval(self, milliseconds: u64) -> Self
pub fn poll_interval(self, milliseconds: u64) -> Self
Sets the idle polling interval in milliseconds.
Sourcepub fn max_concurrency(self, limit: usize) -> Self
pub fn max_concurrency(self, limit: usize) -> Self
Sets the hard upper bound for simultaneously executing handlers.
Sourcepub fn job_timeout(self, timeout: Duration) -> Self
pub fn job_timeout(self, timeout: Duration) -> Self
Sets the maximum duration of an individual handler execution.
A handler still running at the deadline is aborted and its job is failed as timed out. A handler that cannot be interrupted (for example one that blocks its thread) and then returns is recorded from its own result instead.
Sourcepub fn stalled_after(self, age: Duration) -> Self
pub fn stalled_after(self, age: Duration) -> Self
Sets the age after which a processing lease counts as stalled.
The worker returns stalled leases to pending when it starts and then
every min(age, 60 s) (at least every second). Recovery is queue-wide:
it covers every processing lease in the shared SQLite table or Redis
namespace, including leases held by other workers. age must exceed
this worker’s Self::job_timeout, and every worker sharing a queue
must use an age longer than the longest job_timeout among them, or
a worker with a short age requeues another worker’s running job and
it runs twice.
Sourcepub fn register<F, Fut>(
&mut self,
name: impl Into<String>,
handler: F,
) -> &mut Self
pub fn register<F, Fut>( &mut self, name: impl Into<String>, handler: F, ) -> &mut Self
Registers a handler for a job name.
Sourcepub fn run(&self) -> Result<WorkerHandle, QueueError>
pub fn run(&self) -> Result<WorkerHandle, QueueError>
Starts the polling loop and returns an observable lifecycle handle.
§Errors
Returns a typed error for zero concurrency, a zero polling interval, or invocation outside an active Tokio runtime. No task is spawned on error.