Struct apalis_core::builder::WorkerBuilder
source · pub struct WorkerBuilder<T, S, M> { /* private fields */ }Expand description
Configure and build a Worker job service.
WorkerBuilder collects all the components and configuration required to
build a job service. Once the service is defined, it can be built
with build.
Examples
Defining a job service with the default [JobService];
use apalis::prelude::*;
use apalis::sqlite::SqliteStorage;
let sqlite = SqliteStorage::new("sqlite::memory:").await.unwrap();
async fn email_service(job: JobRequest<Email>) -> Result<JobResult, JobError> {
Ok(JobResult::Success)
}
let addr = WorkerBuilder::new(sqlite)
.build_fn(email_service)
.start().await;
Defining a middleware stack
use apalis::layers::{
extensions::Extension,
retry::{JobRetryPolicy, RetryLayer},
};
use apalis::WorkerBuilder;
use apalis::sqlite::SqliteStorage;
let sqlite = SqliteStorage::connect("sqlite::memory:").await.unwrap();
#[derive(Clone)]
struct JobState {}
let addr = WorkerBuilder::new(sqlite)
.layer(RetryLayer::new(JobRetryPolicy))
.layer(Extension(JobState {}))
.build()
.start().await;
Implementations§
source§impl<S> WorkerBuilder<(), S, Identity>
impl<S> WorkerBuilder<(), S, Identity>
sourcepub fn new(source: S) -> WorkerBuilder<S::Job, S, Identity>where
S: JobStream,
pub fn new(source: S) -> WorkerBuilder<S::Job, S, Identity>where
S: JobStream,
Build a new WorkerBuilder instance
source§impl<T, S, M> WorkerBuilder<T, S, M>
impl<T, S, M> WorkerBuilder<T, S, M>
sourcepub fn layer<U>(self, layer: U) -> WorkerBuilder<T, S, Stack<U, M>>where
M: Layer<U>,
pub fn layer<U>(self, layer: U) -> WorkerBuilder<T, S, Stack<U, M>>where
M: Layer<U>,
Add a new layer T into the WorkerBuilder.
This wraps the inner service with the service provided by a user-defined [Layer]. The provided layer must implement the [Layer] trait.
sourcepub fn filter<P>(
self,
predicate: P
) -> WorkerBuilder<T, S, Stack<FilterLayer<P>, M>>where
M: Layer<FilterLayer<P>>,
Available on crate feature filter only.
pub fn filter<P>(
self,
predicate: P
) -> WorkerBuilder<T, S, Stack<FilterLayer<P>, M>>where
M: Layer<FilterLayer<P>>,
filter only.Conditionally reject requests based on predicate.
predicate must implement the [Predicate] trait.
This wraps the inner service with an instance of the Filter
middleware.
sourcepub fn filter_async<P>(
self,
predicate: P
) -> WorkerBuilder<T, S, Stack<AsyncFilterLayer<P>, M>>where
M: Layer<AsyncFilterLayer<P>>,
pub fn filter_async<P>(
self,
predicate: P
) -> WorkerBuilder<T, S, Stack<AsyncFilterLayer<P>, M>>where
M: Layer<AsyncFilterLayer<P>>,
Conditionally reject requests based on an asynchronous predicate.
predicate must implement the [AsyncPredicate] trait.
This wraps the inner service with an instance of the [AsyncFilter]
middleware.
[AsyncFilter]: tower::filter::
sourcepub fn map_response<F>(
self,
f: F
) -> WorkerBuilder<T, S, Stack<MapResponseLayer<F>, M>>where
M: Layer<MapResponseLayer<F>>,
pub fn map_response<F>(
self,
f: F
) -> WorkerBuilder<T, S, Stack<MapResponseLayer<F>, M>>where
M: Layer<MapResponseLayer<F>>,
Map one response type to another.
This wraps the inner service with an instance of the MapResponse
middleware.
See the documentation for the map_response combinator for details.
sourcepub fn map_err<F>(self, f: F) -> WorkerBuilder<T, S, Stack<MapErrLayer<F>, M>>where
M: Layer<MapErrLayer<F>>,
pub fn map_err<F>(self, f: F) -> WorkerBuilder<T, S, Stack<MapErrLayer<F>, M>>where
M: Layer<MapErrLayer<F>>,
Map one error type to another.
This wraps the inner service with an instance of the MapErr
middleware.
See the documentation for the map_err combinator for details.
Trait Implementations§
source§impl<T, S, M, Ser, Fut> WorkerFactory<Ser> for WorkerBuilder<T, S, M>where
S: Storage<Output = T> + Unpin + Send + 'static + Sync,
T: Job + Send + 'static,
M: Layer<Ser>,
<M as Layer<Ser>>::Service: Service<JobRequest<T>, Response = JobResult, Error = JobError, Future = Fut> + Unpin + Send + 'static,
Fut: Future<Output = Result<JobResult, JobError>> + Send,
Available on crate feature storage only.
impl<T, S, M, Ser, Fut> WorkerFactory<Ser> for WorkerBuilder<T, S, M>where
S: Storage<Output = T> + Unpin + Send + 'static + Sync,
T: Job + Send + 'static,
M: Layer<Ser>,
<M as Layer<Ser>>::Service: Service<JobRequest<T>, Response = JobResult, Error = JobError, Future = Fut> + Unpin + Send + 'static,
Fut: Future<Output = Result<JobResult, JobError>> + Send,
storage only.Auto Trait Implementations§
impl<T, S, M> RefUnwindSafe for WorkerBuilder<T, S, M>where
M: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S, M> Send for WorkerBuilder<T, S, M>where
M: Send,
S: Send,
T: Send,
impl<T, S, M> Sync for WorkerBuilder<T, S, M>where
M: Sync,
S: Sync,
T: Sync,
impl<T, S, M> Unpin for WorkerBuilder<T, S, M>where
M: Unpin,
S: Unpin,
T: Unpin,
impl<T, S, M> UnwindSafe for WorkerBuilder<T, S, M>where
M: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
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> 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>
§impl<T> Pointable for T
impl<T> Pointable for T
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<W, F> WorkerFactoryFn<F> for Wwhere
W: WorkerFactory<JobFn<F>>,
impl<W, F> WorkerFactoryFn<F> for Wwhere
W: WorkerFactory<JobFn<F>>,
§type Worker = <W as WorkerFactory<JobFn<F>>>::Worker
type Worker = <W as WorkerFactory<JobFn<F>>>::Worker
source§fn build_fn(self, f: F) -> <W as WorkerFactoryFn<F>>::Worker
fn build_fn(self, f: F) -> <W as WorkerFactoryFn<F>>::Worker
build method Read more