From 6adab1b903eb185486d530b8b956ae89b5e9dae8 Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 6 Feb 2025 14:37:17 +0300 Subject: [PATCH] joinhandlers ending is catching and processing --- noxis-rs/settings.json | 2 +- noxis-rs/src/options/config.rs | 74 ++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/noxis-rs/settings.json b/noxis-rs/settings.json index f5fab28..2b5f808 100644 --- a/noxis-rs/settings.json +++ b/noxis-rs/settings.json @@ -1,5 +1,5 @@ { - "dateOfCreation": "1721381809106", + "dateOfCreation": "1721381809107", "configServer": "localhost", "processes": [ { diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index 44cebcd..88fdbe7 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -44,25 +44,30 @@ pub mod v2 { // dbg!("before lc"); let params_clone = params.clone(); + let for_lc_path = params.clone(); + let lc_path = for_lc_path + .config + .to_str() + .unwrap_or("settings.json"); // future to init work with local config let lc_future = tokio::spawn(async move { // let params = params.clone(); - let _ = local_config_reciever( + local_config_reciever( params_clone, rx_pb_lc, rx_cli_lc, Arc::new(brd_tx) - ).await; + ).await }); // dbg!("before pb"); // future to init work with pub sub mechanism let pubsub_future = tokio::spawn(async move { - let _ = pubsub_config_reciever( + pubsub_config_reciever( tx_pb_lc, params.clone(), local_config_brd_reciever - ).await; + ).await }); // dbg!("before cli"); @@ -71,15 +76,68 @@ pub mod v2 { from_cli_config_reciever( cli_oneshot, tx_cli_lc - ).await; + ).await }); // let _ = lc_future.await; // dbg!("before select"); tokio::select! { - lc_result = lc_future => {dbg!("end of lc");}, - pb_result = pubsub_future => {dbg!("end of pb");}, - cli_config_option = cli_future => {dbg!("end of cli");}, + lc_result = lc_future => { + // dbg!("end of lc"); + match lc_result { + Ok(res) => { + if res.is_ok() { + info!("Local config warding mechanism stopped, waiting for others ..."); + sleep(Duration::from_millis(500)).await; + } + else { + error!("Local config warding mechanism crushed, restarting ..."); + let _ = restart_main_thread(); + } + }, + Err(_) => { + error!("Local config warding mechanism crushed, restarting ..."); + let _ = restart_main_thread(); + }, + } + }, + pb_result = pubsub_future => { + match pb_result { + Ok(res) => { + if res.is_ok() { + info!("New config was saved locally, restarting ..."); + } + else { + error!("Pubsub mechanism crushed, restarting ..."); + } + }, + Err(_) => { + error!("Pubsub mechanism crushed, restarting ..."); + }, + } + let _ = restart_main_thread(); + }, + cli_config_option = cli_future => { + // match cli_config_option { + // Some(config) => {}, + // None => { + // error!("Cli pulling new config mechanism crushed, restarting ...") + // }, + // } + match cli_config_option { + Err(_) => error!("Cli pulling new config mechanism crushed, restarting ..."), + Ok(option_config) => { + match option_config { + None => error!("Cli pulling new config mechanism crushed, restarting ..."), + Some(config) => { + info!("New config was pulled from CLI, saving and restarting ..."); + let _ = save_new_config(&config, lc_path); + }, + } + }, + } + let _ = restart_main_thread(); + }, } // dbg!("after select"); // TODO! futures + select! [OK]