fix: 增加触发时间从文件读取的功能
This commit is contained in:
parent
983020b55f
commit
347ea99eeb
|
|
@ -18,6 +18,9 @@ pub struct Config {
|
|||
pub database: String,
|
||||
#[serde(rename = "notifyUrls")]
|
||||
pub notify_urls: Vec<String>,
|
||||
pub pls_cron: Option<String>,
|
||||
pub plw_cron: Option<String>,
|
||||
pub sd_cron: Option<String>,
|
||||
}
|
||||
|
||||
pub fn read_config(file_path: &str) -> Result<Config, Box<dyn Error>> {
|
||||
|
|
|
|||
13
src/main.rs
13
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::<Vec<&str>>();
|
||||
|
|
@ -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::<Vec<&str>>();
|
||||
|
|
@ -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::<Vec<&str>>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue