diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index 4d95aa1..f7b5f26 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -7,10 +7,11 @@ use std::os::unix::process::CommandExt; use std::process::Command; use std::sync::Arc; use std::{env, fs}; -use tokio::time::Duration; +use std::fmt::format; use super::preboot::PrebootParams; +use tokio::time::{Duration, sleep}; -const CONFIG_PATH: &str = "settings.json"; +// const CONFIG_PATH: &str = "settings.json"; /// # Fn `load_processes` /// ## for reading and parsing *local* storing config @@ -70,7 +71,7 @@ pub async fn get_actual_config(params : Arc) -> Option } ConfigActuality::Remote => { info!("Pulled config is more actual. Saving changes!"); - if save_new_config(&remote_conf, CONFIG_PATH).is_err() { + if save_new_config(&remote_conf, config_path).is_err() { error!("Saving changes process failed due to unexpected error...") } Some(remote_conf) @@ -83,11 +84,10 @@ pub async fn get_actual_config(params : Arc) -> Option None => { warn!("No local valid conf was found. Trying to pull remote one..."); if !params.no_remote_config { - let mut conn = get_connection_watcher(&open_watcher("redis://localhost/")); - let remote_config = get_remote_conf_watcher(&mut conn).await; - if let Some(conf) = remote_config { + let mut conn = get_connection_watcher(&open_watcher(&format!("redis://{}/", ¶ms.remote_server_url))); + if let Some(conf) = get_remote_conf_watcher(&mut conn).await { info!("Config {} was pulled from Redis-Server. Starting...", &conf.date_of_creation); - let _ = save_new_config(&conf, CONFIG_PATH); + let _ = save_new_config(&conf, config_path); return Some(conf); } } @@ -189,23 +189,23 @@ fn once_get_remote_configuration(serv_info: &str) -> Option { if remote.is_none() { error!("Pulled config is invalid. Check it in Redis Server"); } - return remote; + remote }, Err(_) => { error!("Cannot extract payload from new message. Check Redis Server state"); - return None; + None }, } }, Err(_) => { warn!("Cannot get config from Redis Server. Empty channel"); - return None; + None }, } }, Err(_) => { error!("Redis subscription process failed. Check Redis configuration!"); - return None; + None } } } @@ -319,6 +319,8 @@ fn restart_main_thread() -> std::io::Result<()> { /// *depends on* : `Processes` /// pub async fn subscribe_config_stream(actual_prcs: Arc, params: Arc) -> Result<(), CustomError> { + let config_path = params.config.to_str().unwrap_or_else(|| "settings.json"); + if params.no_sub || params.no_remote_config { return Err(CustomError::Fatal); } @@ -340,8 +342,8 @@ pub async fn subscribe_config_stream(actual_prcs: Arc, params: Arc { warn!("Pulled config is actual. Saving and restarting..."); - if save_new_config(&remote_config, CONFIG_PATH).is_err() { - error!("Error with saving new config to {}. Stopping sub mechanism...", &CONFIG_PATH); + if save_new_config(&remote_config, config_path).is_err() { + error!("Error with saving new config to {}. Stopping sub mechanism...", config_path); return Err(CustomError::Fatal); } if restart_main_thread().is_err() { @@ -362,7 +364,7 @@ pub async fn subscribe_config_stream(actual_prcs: Arc, params: Arc Result<(), CustomEr Err(_) => Err(CustomError::Fatal), } } - Err(_) => return Err(CustomError::Fatal), + Err(_) => Err(CustomError::Fatal), } } Err(_) => Err(CustomError::Fatal),