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§

source

type Source

The request source for the Worker

source

type Service

The service that the worker will run jobs against

Required Methods§

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(())
}

Implementors§

source§

impl<J, W, F, K> WorkerFactoryFn<J, F, K> for W
where W: WorkerFactory<J, ServiceFn<F, K>>,

§

type Source = <W as WorkerFactory<J, ServiceFn<F, K>>>::Source

§

type Service = <W as WorkerFactory<J, ServiceFn<F, K>>>::Service