pub trait Worker: Send + Sized + 'static {
    type Job: Job;
    type Service: Service<JobRequest<Self::Job>, Response = JobResult, Error = JobError, Future = Self::Future> + Send;
    type Future: Future<Output = Result<JobResult, JobError>> + Send;

    fn consume(&mut self) -> JobStreamResult<Self::Job>;
    fn service(&mut self) -> &mut Self::Service;

    fn on_start<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
, { ... } fn on_stop<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
, { ... } fn handle_job<'life0, 'async_trait>(
        &'life0 mut self,
        job: JobRequest<Self::Job>
    ) -> Pin<Box<dyn Future<Output = Result<JobResult, JobError>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait
, { ... } fn manage<'life0, 'async_trait>(
        &'life0 mut self,
        _msg: WorkerManagement
    ) -> Pin<Box<dyn Future<Output = Result<WorkerStatus, WorkerError>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait
, { ... } }
Available on crate feature worker only.
Expand description

Worker trait

Required Associated Types§

The job type for the worker

The tower service to process job requests

The future returened by our tower service

Required Methods§

Returns a streams of jobs for the worker to consume

Returns the service that handles the job

Provided Methods§

At start hook of worker

At stop hook of worker

The way the worker will handle a job

Manage a worker

Implementors§