style: code style

This commit is contained in:
2020-10-18 22:46:00 +08:00
parent ad28d12f4c
commit 40748eb3bb

View File

@@ -113,10 +113,10 @@ fn keep_runningd(keep_running_config: Arc<KeepRunningConfig>) {
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let mut fail_count = 0; let mut fail_count = 0;
let check_success = !check_lines.is_empty();
{ // limit `CHECK_FAIL_MAP` lock scope { // limit `CHECK_FAIL_MAP` lock scope
let cloned_title = keep_running_config_item.title.clone(); let cloned_title = keep_running_config_item.title.clone();
let mut check_fail_map = CHECK_FAIL_MAP.lock().unwrap(); let mut check_fail_map = CHECK_FAIL_MAP.lock().unwrap();
let check_success = !check_lines.is_empty();
if check_success { if check_success {
check_fail_map.insert(cloned_title, 0); check_fail_map.insert(cloned_title, 0);
} else { } else {
@@ -127,7 +127,7 @@ fn keep_runningd(keep_running_config: Arc<KeepRunningConfig>) {
} }
} }
if check_lines.is_empty() { // if check fail! if !check_success { // if check fail!
info!("Send DingTalk notification!"); info!("Send DingTalk notification!");
block_send_notify(&keep_running_config.notify_token, &keep_running_config_item.title, fail_count); block_send_notify(&keep_running_config.notify_token, &keep_running_config_item.title, fail_count);
match &keep_running_config_item.restart_command { 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() { match runtime::Builder::new().basic_scheduler().enable_all().build() {
Err(err) => error!("Prepare tokio runtime error: {}", err), Err(err) => error!("Prepare tokio runtime error: {}", err),
Ok(mut rt) => { Ok(mut rt) => {
let mut sb = String::with_capacity(1024); let text = format!("Check failed: {}, fail count: {}\ncheck time: {:?}", title, fail_count, Local::now());
sb.push_str(&format!("Check failed: {}, fail count: {}", title, fail_count)); rt.block_on(send_notify(notify_token, &text));
sb.push_str(&format!("\ncheck time: {:?}", Local::now()));
rt.block_on(send_notify(notify_token, &sb));
}, },
} }
} }