Skip to main content

WorkerBuilder

Struct WorkerBuilder 

Source
pub struct WorkerBuilder<Q: QueueSet, B: Backend> { /* private fields */ }
Expand description

Configures a Worker. Created by Worker::builder.

Implementations§

Source§

impl<Q: QueueSet, B: Backend> WorkerBuilder<Q, B>

Source

pub fn handler<H>(self, handler: H) -> Self
where H: JobHandler, H::Job: Job<Queue = Q>,

Register a handler.

The H::Job: Job<Queue = Q> bound is what makes the worker type-safe: a handler for a job belonging to another queue set does not compile.

Source

pub fn queues(self, queues: &[Q]) -> Self

Consume only these queues instead of every queue in Q. Duplicates are ignored.

Source

pub fn concurrency(self, concurrency: usize) -> Self

Cap the number of jobs running at the same time.

Defaults to the sum of the prefetch of the consumed queues. 0 is treated as 1.

Source

pub fn job_timeout(self, timeout: Duration) -> Self

Abort a handler that runs longer than timeout and treat it as a retryable failure.

Source

pub fn close_backend_on_shutdown(self, close: bool) -> Self

Close the backend when Worker::run returns. Defaults to false.

The backend is an Arc that is normally shared with a crate::Producer (and possibly other workers), so closing it is the caller’s decision: a worker that closed it on its own would take those down with it. Turn this on for a process whose only job is to run this worker, or call backend.close() yourself once run() has returned.

Source

pub async fn build(self) -> Result<Worker<Q, B>>

Declare the queues and produce the Worker.

Fails with Error::DuplicateHandler if two handlers claim the same Job::NAME.

Auto Trait Implementations§

§

impl<Q, B> !RefUnwindSafe for WorkerBuilder<Q, B>

§

impl<Q, B> !UnwindSafe for WorkerBuilder<Q, B>

§

impl<Q, B> Freeze for WorkerBuilder<Q, B>
where Arc<B>: Freeze, Option<Vec<Q>>: Freeze,

§

impl<Q, B> Send for WorkerBuilder<Q, B>
where Arc<B>: Send, Option<Vec<Q>>: Send,

§

impl<Q, B> Sync for WorkerBuilder<Q, B>
where Arc<B>: Sync, Option<Vec<Q>>: Sync,

§

impl<Q, B> Unpin for WorkerBuilder<Q, B>
where Arc<B>: Unpin, Option<Vec<Q>>: Unpin,

§

impl<Q, B> UnsafeUnpin for WorkerBuilder<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