pub trait Worker:
Send
+ Sync
+ 'static {
// Required methods
fn kind(&self) -> &'static str;
fn perform<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 JobContext,
) -> Pin<Box<dyn Future<Output = Result<JobResult, JobError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Worker trait — implement this for each job type.
§Handling permanent failure
When all retry attempts are exhausted, awa moves the job to failed.
To run cleanup logic (update external state, send notifications), check
the attempt count inside perform:
ⓘ
async fn perform(&self, ctx: &JobContext) -> Result<JobResult, JobError> {
match do_work(ctx).await {
Ok(()) => Ok(JobResult::Completed),
Err(err) if ctx.job.attempt >= ctx.job.max_attempts => {
// Last attempt — run cleanup before awa marks as failed
mark_permanently_failed(ctx.job.id).await;
Err(JobError::retryable(err))
}
Err(err) => Err(JobError::retryable(err)),
}
}Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".