pub struct WorkerBuilder<Args, Source, Middleware> { /* private fields */ }Expand description
Declaratively builds a Worker
Implementations§
Source§impl WorkerBuilder<(), (), Identity>
impl WorkerBuilder<(), (), Identity>
Sourcepub fn new<T>(name: T) -> WorkerBuilder<(), (), Identity>where
T: Into<WorkerContext>,
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>
impl WorkerBuilder<(), (), Identity>
Sourcepub fn backend<NB, NJ>(self, backend: NB) -> WorkerBuilder<NJ, NB, Identity>where
NB: Backend + BackendConfig<Args = NJ>,
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,
impl<Args, M, B> WorkerBuilder<Args, B, M>where
B: Backend,
Sourcepub fn chain<NewLayer>(
self,
f: impl FnOnce(M) -> NewLayer,
) -> WorkerBuilder<Args, B, NewLayer>
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
Sourcepub fn layer<U>(self, layer: U) -> WorkerBuilder<Args, B, Stack<U, M>>
pub fn layer<U>(self, layer: U) -> WorkerBuilder<Args, B, Stack<U, M>>
Allows adding middleware to the layer stack
Sourcepub fn data<D>(self, data: D) -> WorkerBuilder<Args, B, Stack<Data<D>, M>>
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
impl<Args, B, M> WorkerBuilder<Args, B, M>
Finalizes the builder and constructs a Worker with the provided service
Sourcepub 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,
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>
impl<Args, B, M, Ack, Res> AcknowledgementExt<Args, B, M, Ack, Res> for WorkerBuilder<Args, B, M>
Source§fn ack_with(
self,
ack: Ack,
) -> WorkerBuilder<Args, B, Stack<AcknowledgeLayer<Ack>, M>>
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>
impl<Args, P, M> CircuitBreaker<Args, P, M> for WorkerBuilder<Args, P, M>
Source§fn break_circuit_with(
self,
config: CircuitBreakerConfig,
) -> WorkerBuilder<Args, P, Stack<CircuitBreakerLayer, M>>
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>>
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>
impl<Args, Source, Middleware> Debug for WorkerBuilder<Args, Source, Middleware>
Source§impl<Args, P, M> EventListenerExt<Args, P, M> for WorkerBuilder<Args, P, M>where
P: Backend,
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>>
fn on_event<F>( self, f: F, ) -> WorkerBuilder<Args, P, Stack<EventListenerLayer, M>>
Register a callback for worker events
Source§impl<Args, B, M> LongRunningExt<Args, B, M> for WorkerBuilder<Args, B, M>
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>>
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>>
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>
impl<Args, P, M, Executor> ParallelizeExt<Args, P, M, Executor> for WorkerBuilder<Args, P, M>
Source§fn parallelize(
self,
f: Executor,
) -> WorkerBuilder<Args, P, Stack<ParallelizeLayer<Executor>, M>>
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,
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>>
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>>
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>>
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>>
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>>
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>>
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>>
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>>
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>>
fn map_request<F, R1, R2>( self, f: F, ) -> WorkerBuilder<Args, Source, Stack<MapRequestLayer<F>, Middleware>>
Maps one request type to another.
Source§fn map_response<F>(
self,
f: F,
) -> WorkerBuilder<Args, Source, Stack<MapResponseLayer<F>, Middleware>>
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>>
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>>
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>>
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>>
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>>
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>
impl<B> WorkerFromConfig<B> for WorkerBuilder<(), (), Identity>
Source§fn try_config(
config: WorkerConfig<B>,
) -> Result<WorkerBuilder<<<B as TryNewBackend>::Backend as BackendConfig>::Args, <B as TryNewBackend>::Backend, Stack<MiddlewareStack<<B as TryNewBackend>::Backend>, Identity>>, <B as Backend>::Error>
fn try_config( config: WorkerConfig<B>, ) -> Result<WorkerBuilder<<<B as TryNewBackend>::Backend as BackendConfig>::Args, <B as TryNewBackend>::Backend, Stack<MiddlewareStack<<B as TryNewBackend>::Backend>, Identity>>, <B as Backend>::Error>
Attempt to build a
WorkerBuilder from the given WorkerConfig.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>
impl<Args, Source, Middleware> Move for WorkerBuilder<Args, Source, Middleware>
impl<Args, Source, Middleware> Send for WorkerBuilder<Args, Source, Middleware>
impl<Args, Source, Middleware> Sync for WorkerBuilder<Args, Source, Middleware>
impl<Args, Source, Middleware> Unpin for WorkerBuilder<Args, Source, Middleware>
impl<Args, Source, Middleware> UnsafeUnpin for WorkerBuilder<Args, Source, Middleware>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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