oxanus/
worker.rs

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        // 0 -> 25 seconds
19        // 1 -> 125 seconds
20        // 2 -> 625 seconds
21        // 3 -> 3125 seconds
22        // 4 -> 15625 seconds
23        // 5 -> 78125 seconds
24        // 6 -> 390625 seconds
25        // 7 -> 1953125 seconds
26        u64::pow(5, retries + 2)
27    }
28
29    fn unique_id(&self) -> Option<String> {
30        None
31    }
32}