1use crate::context::Context;
2use std::panic::UnwindSafe;
3
4pub type BoxedWorker<DT, ET> = Box<dyn Worker<Context = DT, Error = ET>>;
5
6#[async_trait::async_trait]
7pub trait Worker: Send + Sync + UnwindSafe {
8 type Context: Clone + Send + Sync;
9 type Error: std::error::Error + Send + Sync;
10
11 async fn process(&self, data: &Context<Self::Context>) -> Result<(), Self::Error>;
12
13 fn max_retries(&self) -> u32 {
14 1
15 }
16
17 fn retry_delay(&self, retries: u32) -> u64 {
18 u64::pow(5, retries + 2)
27 }
28
29 fn unique_id(&self) -> Option<String> {
30 None
31 }
32}