pub struct Worker<Q: QueueSet, B: Backend> { /* private fields */ }Expand description
Consumes one or more queues of Q and dispatches jobs to registered handlers.
Build one with Worker::builder; run it with Worker::run.
Implementations§
Source§impl<Q: QueueSet, B: Backend> Worker<Q, B>
impl<Q: QueueSet, B: Backend> Worker<Q, B>
Sourcepub fn builder(backend: Arc<B>) -> WorkerBuilder<Q, B>
pub fn builder(backend: Arc<B>) -> WorkerBuilder<Q, B>
Start configuring a worker for queue set Q on backend.
Sourcepub fn handle(&self) -> WorkerHandle
pub fn handle(&self) -> WorkerHandle
A clonable handle that can shut this worker down from anywhere.
Sourcepub fn queues(&self) -> &[QueueConfig]
pub fn queues(&self) -> &[QueueConfig]
The queues this worker consumes.
Sourcepub fn concurrency(&self) -> usize
pub fn concurrency(&self) -> usize
Maximum number of jobs this worker runs at the same time.
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Consume and dispatch until WorkerHandle::shutdown is called.
Shutdown is graceful, and in this order:
- the consumers stop pulling new deliveries from the broker;
- everything they already pulled is processed normally (a delivery that has been handed over is never dropped unsettled);
- the jobs already running are awaited.
The backend is not closed unless
WorkerBuilder::close_backend_on_shutdown was set: it is usually an
Arc shared with a crate::Producer that outlives the worker.
Returns Error::ConsumerStopped if a consumer stream ends on its own (which
means the backend went away), or the first backend error seen on a stream.
Trait Implementations§
Auto Trait Implementations§
impl<Q, B> !RefUnwindSafe for Worker<Q, B>
impl<Q, B> !UnwindSafe for Worker<Q, B>
impl<Q, B> Freeze for Worker<Q, B>
impl<Q, B> Send for Worker<Q, B>
impl<Q, B> Sync for Worker<Q, B>
impl<Q, B> Unpin for Worker<Q, B>
impl<Q, B> UnsafeUnpin for Worker<Q, B>
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