From 347ea99eeb21e7e8c861ebb8b967c9ca5647f666 Mon Sep 17 00:00:00 2001 From: chenwj Date: Fri, 9 Aug 2024 14:06:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=BB=8E=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/config.rs | 3 +++ src/main.rs | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) 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::>();