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
Trait for executing jobs
Implementations of this trait define how specific job types are executed. The worker receives the job and its arguments, and returns a result.
Required Methods§
Sourcefn 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 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,
Sourcefn method_name(&self) -> &str
fn method_name(&self) -> &str
Get the method name this worker handles
Provided Methods§
Sourcefn can_handle(&self, method: &str) -> bool
fn can_handle(&self, method: &str) -> bool
Check if this worker can handle the given job method