2022-08-29 16:59:22 +00:00
|
|
|
use crate::queue::Queueable;
|
2022-08-31 17:45:13 +00:00
|
|
|
use crate::FangError;
|
2022-08-29 16:59:22 +00:00
|
|
|
use crate::Scheduled;
|
|
|
|
|
|
|
|
pub const COMMON_TYPE: &str = "common";
|
2022-09-17 16:39:47 +00:00
|
|
|
pub const RETRIES_NUMBER: i32 = 20;
|
2022-08-29 16:59:22 +00:00
|
|
|
|
|
|
|
#[typetag::serde(tag = "type")]
|
|
|
|
pub trait Runnable {
|
2022-08-31 17:45:13 +00:00
|
|
|
fn run(&self, _queueable: &dyn Queueable) -> Result<(), FangError>;
|
2022-08-29 16:59:22 +00:00
|
|
|
|
|
|
|
fn task_type(&self) -> String {
|
|
|
|
COMMON_TYPE.to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn uniq(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cron(&self) -> Option<Scheduled> {
|
|
|
|
None
|
|
|
|
}
|
2022-09-17 16:39:47 +00:00
|
|
|
|
|
|
|
fn max_retries(&self) -> i32 {
|
|
|
|
RETRIES_NUMBER
|
|
|
|
}
|
|
|
|
|
|
|
|
fn backoff(&self, attempt: u32) -> u32 {
|
|
|
|
u32::pow(2, attempt)
|
|
|
|
}
|
2022-08-29 16:59:22 +00:00
|
|
|
}
|