[][src]Struct background_jobs::WorkerConfig

pub struct WorkerConfig<State> where
    State: Clone + 'static, 
{ /* fields omitted */ }

Worker Configuration

This type is used for configuring and creating workers to process jobs. Before starting the workers, register Processor types with this struct. This worker registration allows for different worker processes to handle different sets of workers.

Methods

impl<State> WorkerConfig<State> where
    State: Clone + 'static, 
[src]

pub fn new(
    state_fn: impl Send + Sync + Fn() -> State + 'static
) -> WorkerConfig<State>
[src]

Create a new WorkerConfig

The supplied function should return the State required by the jobs intended to be processed. The function must be sharable between threads, but the state itself does not have this requirement.

pub fn register<P, J>(self, processor: P) -> WorkerConfig<State> where
    J: Job<State = State>,
    P: Processor<Job = J> + Send + Sync + 'static,
    <<J as Job>::Future as IntoFuture>::Future: Send
[src]

Register a Processor with the worker

This enables the worker to handle jobs associated with this processor. If a processor is not registered, none of it's jobs will be run, even if another processor handling the same job queue is registered.

pub fn set_processor_count(self, queue: &str, count: u64) -> WorkerConfig<State>[src]

Set the number of workers to run for a given queue

This does not spin up any additional threads. The Arbiter the workers are spawned onto will handle processing all workers, regardless of how many are configured.

By default, 4 workers are spawned

pub fn start(self, queue_handle: QueueHandle)[src]

Start the workers in the current arbiter

pub fn start_in_arbiter(self, arbiter: &Arbiter, queue_handle: QueueHandle)[src]

Start the workers in the provided arbiter

Trait Implementations

impl<State> Clone for WorkerConfig<State> where
    State: Clone + 'static, 
[src]

Auto Trait Implementations

impl<State> Send for WorkerConfig<State>

impl<State> Unpin for WorkerConfig<State>

impl<State> Sync for WorkerConfig<State>

impl<State> !UnwindSafe for WorkerConfig<State>

impl<State> !RefUnwindSafe for WorkerConfig<State>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,