diff --git a/src/config.rs b/src/config.rs index efb8f3f..0fb7934 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,13 +1,13 @@ use crate::structs::*; use log::{error, info, warn}; use redis::{Client, Commands, Connection, RedisResult}; -use std::{env, fs}; use std::os::unix::process::CommandExt; use std::process::Command; use std::sync::Arc; +use std::{env, fs}; use tokio::time::Duration; -static CONFIG_PATH: &str = "settings.json"; +const CONFIG_PATH: &str = "settings.json"; type Res = RedisResult)>>>; // 4ever sync @@ -25,7 +25,10 @@ pub fn get_actual_config() -> Option { // let mut local = load_processes(&CONFIG_PATH); match load_processes(CONFIG_PATH) { Some(local_conf) => { - info!("Found local configuration, version - {}", &local_conf.date_of_creation); + info!( + "Found local configuration, version - {}", + &local_conf.date_of_creation + ); if let Some(remote_conf) = once_get_remote_configuration("redis://localhost") { return match config_comparing(&local_conf, &remote_conf) { ConfigActuality::Local => { @@ -80,9 +83,12 @@ fn once_get_remote_configuration(serv_info: &str) -> Option { } match parse_extern_config(&config[0].1[0].1) { Some(prcs) => { - info!("Config {} was pulled from Redis-Server", &prcs.date_of_creation); + info!( + "Config {} was pulled from Redis-Server", + &prcs.date_of_creation + ); Some(prcs) - }, + } None => { error!("Invalid configuration was pulled (PARSING_ERROR). Check configs state!"); None @@ -159,7 +165,10 @@ fn get_stream_info_watcher(conn: &mut Connection) { fn invalid_config_watcher(conn: &mut Connection) -> Processes { loop { if let Some(prcs) = get_remote_config(conn) { - info!("Got new config from Redis-Server, version - {}", &prcs.date_of_creation); + info!( + "Got new config from Redis-Server, version - {}", + &prcs.date_of_creation + ); return prcs; } error!("Got INVALID configuration. Update config! Retrying..."); @@ -180,10 +189,9 @@ fn get_remote_config(conn: &mut Connection) -> Option { None } -fn restart_main_thread() -> std::io::Result<()>{ +fn restart_main_thread() -> std::io::Result<()> { let current_exe = env::current_exe()?; - Command::new(current_exe) - .exec(); + Command::new(current_exe).exec(); Ok(()) } pub async fn subscribe_config_stream(actual_prcs: Arc) -> Result<(), CustomError> { @@ -198,13 +206,13 @@ pub async fn subscribe_config_stream(actual_prcs: Arc) -> Result<(), info!("New config was pulled. Saving and restarting..."); if save_new_config(&prcs, CONFIG_PATH).is_err() { error!("Error with saving new config to {}", &CONFIG_PATH); - return Err(CustomError::Fatal) + return Err(CustomError::Fatal); } if restart_main_thread().is_err() { error!("Error with restarting Runner. Stopping sub mechanism..."); - return Err(CustomError::Fatal) + return Err(CustomError::Fatal); } - }, + } _ => continue, } return Ok(()); @@ -245,7 +253,7 @@ fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomEr } fn parse_extern_config(json_string: &str) -> Option { - if let Ok(des) = serde_json::from_str::(json_string){ + if let Ok(des) = serde_json::from_str::(json_string) { return Some(des); } None diff --git a/src/main.rs b/src/main.rs index 6c79294..529983e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,9 +69,9 @@ async fn main() { // destructor addition handler.push(tokio::spawn(async move { - if let Err(_) = set_valid_destructor(Arc::new(senders)).await { + if set_valid_destructor(Arc::new(senders)).await.is_err() { error!("Linux signals handler creation failed. Terminating main thread..."); - return; + return } // todo: rework this temp construction, use async/await in signals mod tokio::time::sleep(Duration::from_millis(200)).await; @@ -81,8 +81,8 @@ async fn main() { // remote config update subscription handler.push(tokio::spawn(async move { - if let Err(_) = subscribe_config_stream(Arc::new(processes)).await { - return; + if subscribe_config_stream(Arc::new(processes)).await.is_err() { + return } })); diff --git a/src/signals.rs b/src/signals.rs index fa7fd75..aaae61a 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -66,7 +66,7 @@ trait SigPostProcessing { impl SigPostProcessing for Sig { async fn post_processing(&mut self) -> io::Result<()> { // manipulations ... - if let Some(_) = self.signal.recv().await { + if self.signal.recv().await.is_some() { log::info!("Got {} signal", self.sig_type); for prc in self.senders.clone().iter() { let _ = prc.send(111).await; diff --git a/src/utils.rs b/src/utils.rs index 6322232..c8915f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -14,12 +14,12 @@ use tokio::join; use tokio::sync::mpsc; use tokio::time::Duration; -static GET_ID_CMD: &str = +const GET_ID_CMD: &str = r"cat /proc/self/mountinfo | grep '/docker/containers/' | head -1 | awk -F '/' '{print \$6}'"; /// # async func to run 3 main daemons (now it's more like tree-form than classical 0.1.0 form ) /// > hint : give mpsc with capacity 1 to jump over potential errors during running process -/// ** in [developing](https://github.com/prplV/runner-rs "REPOSITORY") ** +/// > ** in [developing](https://github.com/prplV/runner-rs "REPOSITORY") ** pub async fn run_daemons( proc: Arc, tx: Arc>, @@ -32,7 +32,7 @@ pub async fn run_daemons( } let watchers_clone: Arc>> = Arc::new(tokio::sync::Mutex::new(watchers)); - + loop { let run_hand = running_handler(proc.clone(), tx.clone(), watchers_clone.clone()); tokio::select! {