diff --git a/src/config/config.rs b/src/config/config.rs index f99c2b5..9cbea68 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -18,6 +18,9 @@ pub struct Config { pub database: String, #[serde(rename = "notifyUrls")] pub notify_urls: Vec, + pub pls_cron: Option, + pub plw_cron: Option, + pub sd_cron: Option, } pub fn read_config(file_path: &str) -> Result> { diff --git a/src/main.rs b/src/main.rs index 8cd0f6a..7b8fddc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,9 +19,16 @@ fn main() { "/etc/sched_rs/config.toml" }; let config = config::read_config(file_path).unwrap(); + // 读取配置文件定时任务触发时间 + let config_clone = config.clone(); + let pls_cron = config_clone.pls_cron.unwrap_or("00:01:00".to_string()); + let plw_cron = config_clone.plw_cron.unwrap_or("00:01:15".to_string()); + let sd_cron = config_clone.sd_cron.unwrap_or("00:01:30".to_string()); + + // 在多个定时任务之间分享配置信息 let config = Arc::new(config); let clone_config1 = Arc::clone(&config); - scheduler.every(1.day()).at("00:01:00").run(move|| { + scheduler.every(1.day()).at(&pls_cron).run(move|| { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let notify_urls = clone_config1.notify_urls.iter().map(|url| url.as_str()).collect::>(); @@ -49,7 +56,7 @@ fn main() { }) }); let clone_config2 = Arc::clone(&config); - scheduler.every(1.day()).at("00:01:15").run(move|| { + scheduler.every(1.day()).at(&plw_cron).run(move|| { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let notify_urls = clone_config2.notify_urls.iter().map(|url| url.as_str()).collect::>(); @@ -77,7 +84,7 @@ fn main() { }) }); let clone_config3 = Arc::clone(&config); - scheduler.every(1.day()).at("00:01:30").run(move|| { + scheduler.every(1.day()).at(&sd_cron).run(move|| { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let notify_urls = clone_config3.notify_urls.iter().map(|url| url.as_str()).collect::>();