From 40748eb3bb005d140318df3635328aa68d74843e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 18 Oct 2020 22:46:00 +0800 Subject: [PATCH] style: code style --- src/main.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55b34e0..309ddea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,10 +113,10 @@ fn keep_runningd(keep_running_config: Arc) { }).collect::>(); let mut fail_count = 0; + let check_success = !check_lines.is_empty(); { // limit `CHECK_FAIL_MAP` lock scope let cloned_title = keep_running_config_item.title.clone(); let mut check_fail_map = CHECK_FAIL_MAP.lock().unwrap(); - let check_success = !check_lines.is_empty(); if check_success { check_fail_map.insert(cloned_title, 0); } else { @@ -127,7 +127,7 @@ fn keep_runningd(keep_running_config: Arc) { } } - if check_lines.is_empty() { // if check fail! + if !check_success { // if check fail! info!("Send DingTalk notification!"); block_send_notify(&keep_running_config.notify_token, &keep_running_config_item.title, fail_count); match &keep_running_config_item.restart_command { @@ -152,10 +152,8 @@ fn block_send_notify(notify_token: &str, title: &str, fail_count: u64) { match runtime::Builder::new().basic_scheduler().enable_all().build() { Err(err) => error!("Prepare tokio runtime error: {}", err), Ok(mut rt) => { - let mut sb = String::with_capacity(1024); - sb.push_str(&format!("Check failed: {}, fail count: {}", title, fail_count)); - sb.push_str(&format!("\ncheck time: {:?}", Local::now())); - rt.block_on(send_notify(notify_token, &sb)); + let text = format!("Check failed: {}, fail count: {}\ncheck time: {:?}", title, fail_count, Local::now()); + rt.block_on(send_notify(notify_token, &text)); }, } }