use chrono::{DateTime, TimeDelta, Utc};
pub use cron::Schedule;
const ALLOWED_JOB_TIME_DELTA: i64 = 500;
pub trait Job: Send + Sync {
fn execute(&self);
fn should_run(&self) -> bool {
for item in self.schedule().upcoming(Utc).take(1) {
let now = Utc::now();
let difference = item - now;
if difference <= TimeDelta::milliseconds(ALLOWED_JOB_TIME_DELTA) {
return true;
}
}
false
}
fn schedule(&self) -> Schedule;
fn allow_parallel_runs(&self) -> bool {
false
}
fn now(&self) -> DateTime<Utc> {
Utc::now()
}
}
#[allow(dead_code)]
pub(crate) struct IJob {
pub job: Box<dyn Job>,
pub parallel_run_allowed: bool,
}