Skip to main content

WorkerBuilder

Struct WorkerBuilder 

Source
pub struct WorkerBuilder<Args, Source, Middleware> { /* private fields */ }
Expand description

Declaratively builds a Worker

Implementations§

Source§

impl WorkerBuilder<(), (), Identity>

Source

pub fn new<T>(name: T) -> WorkerBuilder<(), (), Identity>
where T: Into<WorkerContext>,

Build a new WorkerBuilder instance with a name for the worker to build

Source§

impl WorkerBuilder<(), (), Identity>

Source

pub fn backend<NB, NJ>(self, backend: NB) -> WorkerBuilder<NJ, NB, Identity>
where NB: Backend + BackendConfig<Args = NJ>,

Set the source to a backend that implements Backend

Source§

impl<Args, M, B> WorkerBuilder<Args, B, M>
where B: Backend,

Source

pub fn chain<NewLayer>( self, f: impl FnOnce(M) -> NewLayer, ) -> WorkerBuilder<Args, B, NewLayer>

Allows of decorating the service that consumes jobs. Allows adding multiple middleware in one call

Source

pub fn layer<U>(self, layer: U) -> WorkerBuilder<Args, B, Stack<U, M>>

Allows adding middleware to the layer stack

Source

pub fn data<D>(self, data: D) -> WorkerBuilder<Args, B, Stack<Data<D>, M>>

Adds data to the context

This will be shared by all requests

Source§

impl<Args, B, M> WorkerBuilder<Args, B, M>

Finalizes the builder and constructs a Worker with the provided service

Source

pub fn build<W, Svc, NB>( self, service: W, ) -> Worker<Args, <W as IntoWorkerService<B, Svc>>::Backend, Svc, M>
where W: IntoWorkerService<B, Svc, Backend = NB>, B: Backend + BackendConfig, NB: Backend + BackendConfig + Send + Unpin, Svc: Service<<NB as Backend>::Task>, Args: Send + 'static,

Consumes the builder and a service to construct the final worker

Trait Implementations§

Source§

impl<Args, B, M, Ack, Res> AcknowledgementExt<Args, B, M, Ack, Res> for WorkerBuilder<Args, B, M>
where M: Layer<AcknowledgeLayer<Ack>>, Ack: Acknowledge<Res>, B: Backend,

Source§

fn ack_with( self, ack: Ack, ) -> WorkerBuilder<Args, B, Stack<AcknowledgeLayer<Ack>, M>>

Add an acknowledgment handler to the worker
Source§

impl<Args, P, M> CircuitBreaker<Args, P, M> for WorkerBuilder<Args, P, M>
where P: Backend, M: Layer<CircuitBreakerLayer>,

Source§

fn break_circuit_with( self, config: CircuitBreakerConfig, ) -> WorkerBuilder<Args, P, Stack<CircuitBreakerLayer, M>>

Allows the worker to break the circuit w in case of failures Allows customizing the CircuitBreakerConfig
Source§

fn break_circuit( self, ) -> WorkerBuilder<Args, Source, Stack<CircuitBreakerLayer, Middleware>>

Allows the worker to break the circuit in case of failures Uses default configuration
Source§

impl<Args, Source, Middleware> Debug for WorkerBuilder<Args, Source, Middleware>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<Args, P, M> EventListenerExt<Args, P, M> for WorkerBuilder<Args, P, M>
where P: Backend,

Source§

fn on_event<F>( self, f: F, ) -> WorkerBuilder<Args, P, Stack<EventListenerLayer, M>>
where F: Fn(&WorkerContext, &Event) + Send + Sync + 'static,

Register a callback for worker events
Source§

impl<Args, B, M> LongRunningExt<Args, B, M> for WorkerBuilder<Args, B, M>

Source§

fn long_running_with_cfg( self, cfg: LongRunningConfig, ) -> WorkerBuilder<Args, B, Stack<LongRunningLayer, M>>

Extension for executing long running jobs with a config
Source§

fn long_running( self, ) -> WorkerBuilder<Args, Source, Stack<LongRunningLayer, Middleware>>

Extension for executing long running jobs
Source§

impl<Args, P, M, Executor> ParallelizeExt<Args, P, M, Executor> for WorkerBuilder<Args, P, M>
where P: Backend, M: Layer<ParallelizeLayer<Executor>>,

Source§

fn parallelize( self, f: Executor, ) -> WorkerBuilder<Args, P, Stack<ParallelizeLayer<Executor>, M>>

Register the executor for parallel task execution.
Source§

impl<Args, Source, Middleware> WorkerBuilderExt<Args, Source, Middleware> for WorkerBuilder<Args, Source, Middleware>
where Source: Backend,

Source§

fn catch_panic( self, ) -> WorkerBuilder<Args, Source, Stack<CatchPanicLayer<fn(&Box<dyn Any + Send>) -> AbortError, AbortError>, Middleware>>

Catch panics in execution and pipe them as errors

Source§

fn enable_tracing( self, ) -> WorkerBuilder<Args, Source, Stack<TraceLayer, Middleware>>

Enable tracing via tracing crate

Source§

fn option_layer<T>( self, layer: Option<T>, ) -> WorkerBuilder<Args, Source, Stack<Either<T, Identity>, Middleware>>

Optionally adds a new layer T into the WorkerBuilder.
Source§

fn layer_fn<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<LayerFn<F>, Middleware>>

Adds a Layer built from a function that accepts a service and returns another service.
Source§

fn concurrency( self, max: usize, ) -> WorkerBuilder<Args, Source, Stack<ConcurrencyLimitLayer, Middleware>>

Limits the max number of in-flight requests.
Source§

fn rate_limit( self, num: u64, per: Duration, ) -> WorkerBuilder<Args, Source, Stack<RateLimitLayer, Middleware>>

Limits requests to at most num per the given duration.
Source§

fn retry<P>( self, policy: P, ) -> WorkerBuilder<Args, Source, Stack<RetryLayer<P>, Middleware>>

Retries failed requests according to the given retry policy.
Source§

fn timeout( self, timeout: Duration, ) -> WorkerBuilder<Args, Source, Stack<TimeoutLayer, Middleware>>

Fails requests that take longer than timeout.
Source§

fn map_request<F, R1, R2>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<MapRequestLayer<F>, Middleware>>
where F: FnMut(R1) -> R2 + Clone,

Maps one request type to another.
Source§

fn map_response<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<MapResponseLayer<F>, Middleware>>

Maps one response type to another.
Source§

fn map_err<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<MapErrLayer<F>, Middleware>>

Maps one error type to another.
Source§

fn map_future<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<MapFutureLayer<F>, Middleware>>

Composes a function that transforms futures produced by the service.
Source§

fn then<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<ThenLayer<F>, Middleware>>

Applies an asynchronous function after the service, regardless of whether the future succeeds or fails.
Source§

fn and_then<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<AndThenLayer<F>, Middleware>>

Executes a new future after this service’s future resolves.
Source§

fn map_result<F>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<MapResultLayer<F>, Middleware>>

Maps the service’s result type to a different value, regardless of success or failure.
Source§

impl<B> WorkerFromConfig<B> for WorkerBuilder<(), (), Identity>

Auto Trait Implementations§

§

impl<Args, Source, Middleware> !RefUnwindSafe for WorkerBuilder<Args, Source, Middleware>

§

impl<Args, Source, Middleware> !UnwindSafe for WorkerBuilder<Args, Source, Middleware>

§

impl<Args, Source, Middleware> Forget for WorkerBuilder<Args, Source, Middleware>

§

impl<Args, Source, Middleware> Freeze for WorkerBuilder<Args, Source, Middleware>
where PhantomData<Args>: Freeze, Middleware: Freeze, Source: Freeze,

§

impl<Args, Source, Middleware> Move for WorkerBuilder<Args, Source, Middleware>

§

impl<Args, Source, Middleware> Send for WorkerBuilder<Args, Source, Middleware>
where Middleware: Send, Source: Send, PhantomData<Args>: Send,

§

impl<Args, Source, Middleware> Sync for WorkerBuilder<Args, Source, Middleware>
where Middleware: Sync, Source: Sync, PhantomData<Args>: Sync,

§

impl<Args, Source, Middleware> Unpin for WorkerBuilder<Args, Source, Middleware>
where Middleware: Unpin, Source: Unpin, PhantomData<Args>: Unpin,

§

impl<Args, Source, Middleware> UnsafeUnpin for WorkerBuilder<Args, Source, Middleware>
where PhantomData<Args>: UnsafeUnpin, Middleware: UnsafeUnpin, Source: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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