Skip to main content

Worker

Trait Worker 

Source
pub trait Worker: Send + Sync {
    // Required methods
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        job: &'life1 Job,
        context: &'life2 WorkerContext,
    ) -> Pin<Box<dyn Future<Output = Result<WorkerResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn method_name(&self) -> &str;

    // Provided method
    fn can_handle(&self, method: &str) -> bool { ... }
}
Expand description

Untyped worker trait — receives the raw Job and its JSON payload.

Most users should prefer TypedWorker, which deserializes the payload into a strongly-typed argument struct before dispatch. Implement Worker directly only when you need the full job metadata or when the payload shape is dynamic.

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, job: &'life1 Job, context: &'life2 WorkerContext, ) -> Pin<Box<dyn Future<Output = Result<WorkerResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute a job.

Source

fn method_name(&self) -> &str

Get the method name this worker handles

Provided Methods§

Source

fn can_handle(&self, method: &str) -> bool

Check if this worker can handle the given job method

Implementors§

Source§

impl<W> Worker for TypedWorkerAdapter<W>
where W: TypedWorker + 'static,