pub trait Worker<Job>: Sized {
    type Service;
    type Source;

    // Required methods
    fn id(&self) -> WorkerId;
    fn start<'async_trait, E>(
        self,
        ctx: WorkerContext<E>
    ) -> Pin<Box<dyn Future<Output = Result<(), WorkerError>> + Send + 'async_trait>>
       where E: 'async_trait + Executor + Send + Sync + 'static,
             Self: 'async_trait;
}
Expand description

The Worker trait represents a type that can execute jobs. It is used to define workers that can be managed by the Monitor.

Each Worker implementation must define a start method that takes a WorkerContext and returns a Result indicating whether the worker was able to execute its jobs successfully or not.

Required Associated Types§

source

type Service

The tower service type that this worker will use to execute jobs.

source

type Source

The source type that this worker will use to receive jobs.

Required Methods§

source

fn id(&self) -> WorkerId

A worker must be identifiable and unique

source

fn start<'async_trait, E>( self, ctx: WorkerContext<E> ) -> Pin<Box<dyn Future<Output = Result<(), WorkerError>> + Send + 'async_trait>>where E: 'async_trait + Executor + Send + Sync + 'static, Self: 'async_trait,

Starts the worker, taking ownership of self and the provided ctx.

This method should run indefinitely or until it returns an error. If an error occurs, it should return a WorkerError describing the reason for the failure.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Strm: Unpin + Send + Stream<Item = Result<Option<Req>, E>> + 'static, Serv: Service<Req, Future = Fut> + Send + 'static, J: Job + 'static, E: 'static + Send + Error + Sync, Req: Send + HasJobContext, Fut: Future + Send + 'static> Worker<J> for ReadyWorker<Strm, Serv>where <Serv as Service<Req>>::Error: Debug,

§

type Service = Serv

§

type Source = Strm