Trait apalis::prelude::WorkerFactoryFn
source · pub trait WorkerFactoryFn<J, F, K> {
type Source;
type Service;
// Required method
fn build_fn(self, f: F) -> Worker<Ready<Self::Service, Self::Source>>;
}
Expand description
Helper trait for building new Workers from WorkerBuilder
Required Associated Types§
Required Methods§
sourcefn build_fn(self, f: F) -> Worker<Ready<Self::Service, Self::Source>>
fn build_fn(self, f: F) -> Worker<Ready<Self::Service, Self::Source>>
Builds a WorkerFactoryFn
using ServiceFn
that can be used to generate new Worker
using the build_fn
method
§Arguments
f
- A functional service.
§Examples
A function can take many forms to allow flexibility
- An async function with a single argument of the item being processed
- An async function with an argument of the item being processed plus up-to 16 arguments that are extracted from the request
Data
A function can return:
- Unit
- primitive
- Result<T, E: Error>
- impl IntoResponse
#[derive(Debug)]
struct Email;
#[derive(Debug)]
struct PgPool;
async fn send_email(email: Email) {
// Implementation of the job function
// ...
}
async fn send_email(email: Email, data: Data<PgPool>) -> Result<(), PgError> {
// Implementation of the job function?
// ...
Ok(())
}