use crate::RUSTBOT_SCHEDULER; use tokio::{ task, time::{ interval, Duration } }; use std::{ sync::Arc, future::Future }; pub struct Scheduler; impl Scheduler { pub fn new() -> Arc { Arc::new(Self) } pub async fn spawn_job( &self, interval_secs: u64, job: Arc F + Send + Sync + 'static> ) where F: Future> + Send + 'static, E: std::fmt::Debug { let mut interval = interval(Duration::from_secs(interval_secs)); loop { interval.tick().await; let job_clone = job.clone(); task::spawn(async move { if let Err(y) = job_clone().await { eprintln!("{RUSTBOT_SCHEDULER}[Job:Error]: {y:?}"); } }); } } }