Trait apalis_core::worker::Worker
source · 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§
Required Methods§
sourcefn consume(&mut self) -> JobStreamResult<Self::Job>
fn consume(&mut self) -> JobStreamResult<Self::Job>
Returns a streams of jobs for the worker to consume
Provided Methods§
sourcefn 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_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,
At start hook of worker
sourcefn 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 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,
At stop hook of worker
sourcefn 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 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,
The way the worker will handle a job
sourcefn 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,
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,
Manage a worker
Implementors§
source§impl<T, S, H, F> Worker for StorageWorker<T, S, H>where
S: JobStream<Job = T> + Storage + Unpin + Storage<Output = T> + Send + 'static + Sync,
T: Job + Send + 'static,
H: Service<JobRequest<T>, Response = JobResult, Error = JobError, Future = F> + Unpin + Send + 'static,
F: Future<Output = Result<JobResult, JobError>> + Send,
Available on crate feature storage only.
impl<T, S, H, F> Worker for StorageWorker<T, S, H>where
S: JobStream<Job = T> + Storage + Unpin + Storage<Output = T> + Send + 'static + Sync,
T: Job + Send + 'static,
H: Service<JobRequest<T>, Response = JobResult, Error = JobError, Future = F> + Unpin + Send + 'static,
F: Future<Output = Result<JobResult, JobError>> + Send,
Available on crate feature
storage only.