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

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§

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 with the given arguments

§Arguments
  • job - The job to execute
  • context - Worker context with execution information
§Returns
  • Ok(WorkerResult) if the job was executed successfully
  • Err(QmlError) if there was an error executing the 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§