2022-07-23 14:24:22 +00:00
|
|
|
use crate::asynk::async_queue::AsyncQueueable;
|
2022-07-17 16:22:00 +00:00
|
|
|
use async_trait::async_trait;
|
2022-08-27 15:58:38 +00:00
|
|
|
use chrono::DateTime;
|
|
|
|
use chrono::Utc;
|
2022-07-17 16:22:00 +00:00
|
|
|
|
|
|
|
const COMMON_TYPE: &str = "common";
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
pub description: String,
|
|
|
|
}
|
|
|
|
|
2022-08-27 15:58:38 +00:00
|
|
|
pub enum Scheduled {
|
|
|
|
CronPattern(String),
|
|
|
|
ScheduleOnce(DateTime<Utc>),
|
|
|
|
}
|
|
|
|
|
2022-07-17 16:22:00 +00:00
|
|
|
#[typetag::serde(tag = "type")]
|
2022-07-31 13:32:37 +00:00
|
|
|
#[async_trait]
|
|
|
|
pub trait AsyncRunnable: Send + Sync {
|
2022-07-23 14:24:22 +00:00
|
|
|
async fn run(&self, client: &mut dyn AsyncQueueable) -> Result<(), Error>;
|
2022-07-17 16:22:00 +00:00
|
|
|
|
|
|
|
fn task_type(&self) -> String {
|
|
|
|
COMMON_TYPE.to_string()
|
|
|
|
}
|
2022-08-27 15:58:38 +00:00
|
|
|
|
|
|
|
fn uniq(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cron(&self) -> Option<Scheduled> {
|
|
|
|
None
|
|
|
|
}
|
2022-07-17 16:22:00 +00:00
|
|
|
}
|