pub struct Worker { /* private fields */ }Expand description
One worker. Cloning is cheap and gives a second worker on the same queue.
Implementations§
Source§impl Worker
impl Worker
pub fn new(queue: Arc<dyn Queue>, registry: Arc<JobRegistry>) -> Self
Sourcepub fn reporting_to(self, store: Arc<dyn ProgressStore>) -> Self
pub fn reporting_to(self, store: Arc<dyn ProgressStore>) -> Self
Give jobs somewhere to report progress. The web process reads the same store, so it must be one both can reach — the database one, unless the worker runs inside the web process.
pub fn on_queue(self, queue: impl Into<String>) -> Self
pub fn poll_interval(self, interval: Duration) -> Self
Sourcepub fn max_jobs(self, count: u64) -> Self
pub fn max_jobs(self, count: u64) -> Self
Stop after count attempts, whatever the shutdown signal says.
pub fn backoff_cap(self, cap: Duration) -> Self
pub fn options(&self) -> &WorkerOptions
Sourcepub async fn run(&self, shutdown: Shutdown) -> Result<WorkerStats>
pub async fn run(&self, shutdown: Shutdown) -> Result<WorkerStats>
Work until shutdown is signalled or max_jobs is reached.
The shutdown check is at the top of the loop and nowhere else. That is the entire graceful-shutdown guarantee: a job already reserved is always run to completion, because there is no point at which the loop can abandon one.
Sourcepub async fn run_once(&self) -> Result<Option<Outcome>>
pub async fn run_once(&self) -> Result<Option<Outcome>>
Reserve and run at most one job. None when the queue had nothing ready.
Sourcepub async fn process(&self, reserved: ReservedJob) -> Result<Outcome>
pub async fn process(&self, reserved: ReservedJob) -> Result<Outcome>
Run one reserved job and settle its fate.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Worker
impl !UnwindSafe for Worker
impl Freeze for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin for Worker
impl UnsafeUnpin for Worker
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
Mutably borrows from an owned value. Read more