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§

Build a new WorkerBuilder instance

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.

Available on crate feature 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.

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::

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.

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§

Formats the value using the given formatter. Read more
The worker to build
Builds a WorkerFactory using a tower service that can be used to generate new Worker actors using the build method Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
The worker build
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