Struct apalis_core::builder::WorkerBuilder
source · pub struct WorkerBuilder<Job, Source, Middleware> { /* private fields */ }Expand description
An abstract that allows building a Worker.
Usually the output is ReadyWorker but you can implement your own via WorkerFactory
Implementations§
source§impl WorkerBuilder<(), (), Identity>
impl WorkerBuilder<(), (), Identity>
sourcepub fn new<T: AsRef<str>>(name: T) -> WorkerBuilder<(), (), Identity>
pub fn new<T: AsRef<str>>(name: T) -> WorkerBuilder<(), (), Identity>
Build a new WorkerBuilder instance with a name for the worker to build
source§impl<J, S, M> WorkerBuilder<J, S, M>
impl<J, S, M> WorkerBuilder<J, S, M>
sourcepub fn stream<NS: Stream<Item = Result<Option<JobRequest<NJ>>, E>>, E, NJ>(
self,
stream: NS
) -> WorkerBuilder<NJ, NS, M>
pub fn stream<NS: Stream<Item = Result<Option<JobRequest<NJ>>, E>>, E, NJ>( self, stream: NS ) -> WorkerBuilder<NJ, NS, M>
Consume a stream directly
sourcepub fn with_stream<NS: Fn(&WorkerId) -> ST, NJ, E, ST: Stream<Item = Result<Option<JobRequest<NJ>>, E>>>(
self,
stream: NS
) -> WorkerBuilder<NJ, ST, M>
pub fn with_stream<NS: Fn(&WorkerId) -> ST, NJ, E, ST: Stream<Item = Result<Option<JobRequest<NJ>>, E>>>( self, stream: NS ) -> WorkerBuilder<NJ, ST, M>
Get the WorkerId and build a stream.
Useful when you want to know what worker is consuming the stream.
source§impl<Job, Stream, Serv> WorkerBuilder<Job, Stream, Serv>
impl<Job, Stream, Serv> WorkerBuilder<Job, Stream, Serv>
sourcepub fn middleware<NewService>(
self,
f: impl Fn(ServiceBuilder<Serv>) -> ServiceBuilder<NewService>
) -> WorkerBuilder<Job, Stream, NewService>
pub fn middleware<NewService>( self, f: impl Fn(ServiceBuilder<Serv>) -> ServiceBuilder<NewService> ) -> WorkerBuilder<Job, Stream, NewService>
Allows of decorating the service that consumes jobs.
Allows adding multiple tower middleware
sourcepub fn layer<U>(self, layer: U) -> WorkerBuilder<Job, Stream, Stack<U, Serv>>where
Serv: Layer<U>,
pub fn layer<U>(self, layer: U) -> WorkerBuilder<Job, Stream, Stack<U, Serv>>where Serv: Layer<U>,
Shorthand for decoration. Allows adding a single layer tower middleware
Trait Implementations§
source§impl<Job, Source, Middleware> Debug for WorkerBuilder<Job, Source, Middleware>
impl<Job, Source, Middleware> Debug for WorkerBuilder<Job, Source, Middleware>
source§impl<J: 'static, M, Mq> WithMq<Stack<Extension<Mq>, Stack<AckLayer<Mq, J>, M>>, Mq> for WorkerBuilder<(), (), M>where
Mq: MessageQueue<J> + Send + Sync + 'static + Clone + Ack<J>,
M: Send + Sync + 'static,
Available on crate feature mq only.
impl<J: 'static, M, Mq> WithMq<Stack<Extension<Mq>, Stack<AckLayer<Mq, J>, M>>, Mq> for WorkerBuilder<(), (), M>where Mq: MessageQueue<J> + Send + Sync + 'static + Clone + Ack<J>, M: Send + Sync + 'static,
Available on crate feature
mq only.§type Stream = Pin<Box<dyn Stream<Item = Result<Option<JobRequest<J>>, JobStreamError>> + Send>>
type Stream = Pin<Box<dyn Stream<Item = Result<Option<JobRequest<J>>, JobStreamError>> + Send>>
The MessageQueue to produce jobs
source§fn with_mq(
self,
mq: Mq
) -> WorkerBuilder<J, Self::Stream, Stack<Extension<Mq>, Stack<AckLayer<Mq, J>, M>>>
fn with_mq( self, mq: Mq ) -> WorkerBuilder<J, Self::Stream, Stack<Extension<Mq>, Stack<AckLayer<Mq, J>, M>>>
The builder method to produce a default WorkerBuilder that will consume jobs
source§impl<J: 'static + Send + Sync, M, ST> WithStorage<Stack<Extension<ST>, Stack<AckLayer<ST, J>, M>>, ST> for WorkerBuilder<(), (), M>where
ST: Storage<Output = J> + Send + Sync + 'static,
M: Send + Sync + 'static,
Available on crate feature storage only.
impl<J: 'static + Send + Sync, M, ST> WithStorage<Stack<Extension<ST>, Stack<AckLayer<ST, J>, M>>, ST> for WorkerBuilder<(), (), M>where ST: Storage<Output = J> + Send + Sync + 'static, M: Send + Sync + 'static,
Available on crate feature
storage only.§type Stream = Pin<Box<dyn Stream<Item = Result<Option<JobRequest<J>>, JobStreamError>> + Send>>
type Stream = Pin<Box<dyn Stream<Item = Result<Option<JobRequest<J>>, JobStreamError>> + Send>>
The source of jobs
source§fn with_storage_config(
self,
storage: ST,
config: impl Fn(WorkerConfig) -> WorkerConfig
) -> WorkerBuilder<J, Self::Stream, Stack<Extension<ST>, Stack<AckLayer<ST, J>, M>>>
fn with_storage_config( self, storage: ST, config: impl Fn(WorkerConfig) -> WorkerConfig ) -> WorkerBuilder<J, Self::Stream, Stack<Extension<ST>, Stack<AckLayer<ST, J>, M>>>
The builder method to produce a configured WorkerBuilder that will consume jobs
source§fn with_storage(self, storage: ST) -> WorkerBuilder<Self::Job, Self::Stream, NS>
fn with_storage(self, storage: ST) -> WorkerBuilder<Self::Job, Self::Stream, NS>
The builder method to produce a default WorkerBuilder that will consume jobs
source§impl<J, S, M, Ser, E, Request> WorkerFactory<J, Ser> for WorkerBuilder<J, S, M>where
S: Stream<Item = Result<Option<Request>, E>> + Send + 'static + Unpin,
J: Job + Send + 'static,
M: Layer<Ser>,
<M as Layer<Ser>>::Service: Service<Request> + Send + 'static,
E: Sync + Send + 'static + Error,
Request: Send + HasJobContext,
<<M as Layer<Ser>>::Service as Service<Request>>::Future: Send + 'static,
Ser: Service<Request>,
<Ser as Service<Request>>::Error: Debug,
<<M as Layer<Ser>>::Service as Service<Request>>::Error: Debug,
impl<J, S, M, Ser, E, Request> WorkerFactory<J, Ser> for WorkerBuilder<J, S, M>where S: Stream<Item = Result<Option<Request>, E>> + Send + 'static + Unpin, J: Job + Send + 'static, M: Layer<Ser>, <M as Layer<Ser>>::Service: Service<Request> + Send + 'static, E: Sync + Send + 'static + Error, Request: Send + HasJobContext, <<M as Layer<Ser>>::Service as Service<Request>>::Future: Send + 'static, Ser: Service<Request>, <Ser as Service<Request>>::Error: Debug, <<M as Layer<Ser>>::Service as Service<Request>>::Error: Debug,
source§fn build(self, service: Ser) -> ReadyWorker<S, <M as Layer<Ser>>::Service>
fn build(self, service: Ser) -> ReadyWorker<S, <M as Layer<Ser>>::Service>
Convert a worker builder to a worker ready to consume jobs
§type Worker = ReadyWorker<S, <M as Layer<Ser>>::Service>
type Worker = ReadyWorker<S, <M as Layer<Ser>>::Service>
The worker to build
Auto Trait Implementations§
impl<Job, Source, Middleware> !RefUnwindSafe for WorkerBuilder<Job, Source, Middleware>
impl<Job, Source, Middleware> Send for WorkerBuilder<Job, Source, Middleware>where Job: Send, Middleware: Send, Source: Send,
impl<Job, Source, Middleware> !Sync for WorkerBuilder<Job, Source, Middleware>
impl<Job, Source, Middleware> Unpin for WorkerBuilder<Job, Source, Middleware>where Job: Unpin, Middleware: Unpin, Source: Unpin,
impl<Job, Source, Middleware> !UnwindSafe for WorkerBuilder<Job, 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
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> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
source§impl<J, W, F> WorkerFactoryFn<J, F> for Wwhere
W: WorkerFactory<J, JobFn<F>>,
impl<J, W, F> WorkerFactoryFn<J, F> for Wwhere W: WorkerFactory<J, JobFn<F>>,
§type Worker = <W as WorkerFactory<J, JobFn<F>>>::Worker
type Worker = <W as WorkerFactory<J, JobFn<F>>>::Worker
The worker build
source§fn build_fn(self, f: F) -> <W as WorkerFactoryFn<J, F>>::Worker
fn build_fn(self, f: F) -> <W as WorkerFactoryFn<J, F>>::Worker
Builds a
WorkerFactoryFn using a crate::job_fn::JobFn service
that can be used to generate new Worker actors using the build method Read more