Skip to main content

Worker

Struct Worker 

Source
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>

Source

pub fn builder(backend: Arc<B>) -> WorkerBuilder<Q, B>

Start configuring a worker for queue set Q on backend.

Source

pub fn handle(&self) -> WorkerHandle

A clonable handle that can shut this worker down from anywhere.

Source

pub fn queues(&self) -> &[QueueConfig]

The queues this worker consumes.

Source

pub fn concurrency(&self) -> usize

Maximum number of jobs this worker runs at the same time.

Source

pub async fn run(self) -> Result<()>

Consume and dispatch until WorkerHandle::shutdown is called.

Shutdown is graceful, and in this order:

  1. the consumers stop pulling new deliveries from the broker;
  2. everything they already pulled is processed normally (a delivery that has been handed over is never dropped unsettled);
  3. 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§

Source§

impl<Q: QueueSet, B: Backend> Debug for Worker<Q, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>
where Arc<B>: Freeze, PhantomData<fn(Q)>: Freeze,

§

impl<Q, B> Send for Worker<Q, B>
where Arc<B>: Send, PhantomData<fn(Q)>: Send,

§

impl<Q, B> Sync for Worker<Q, B>
where Arc<B>: Sync, PhantomData<fn(Q)>: Sync,

§

impl<Q, B> Unpin for Worker<Q, B>
where Arc<B>: Unpin, PhantomData<fn(Q)>: Unpin,

§

impl<Q, B> UnsafeUnpin for Worker<Q, B>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more