joinhandlers ending is catching and processing

feature/configv2
prplV 2025-02-06 14:37:17 +03:00
parent 98da769dd3
commit 6adab1b903
2 changed files with 67 additions and 9 deletions

View File

@ -1,5 +1,5 @@
{ {
"dateOfCreation": "1721381809106", "dateOfCreation": "1721381809107",
"configServer": "localhost", "configServer": "localhost",
"processes": [ "processes": [
{ {

View File

@ -44,25 +44,30 @@ pub mod v2 {
// dbg!("before lc"); // dbg!("before lc");
let params_clone = params.clone(); 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 // future to init work with local config
let lc_future = tokio::spawn(async move { let lc_future = tokio::spawn(async move {
// let params = params.clone(); // let params = params.clone();
let _ = local_config_reciever( local_config_reciever(
params_clone, params_clone,
rx_pb_lc, rx_pb_lc,
rx_cli_lc, rx_cli_lc,
Arc::new(brd_tx) Arc::new(brd_tx)
).await; ).await
}); });
// dbg!("before pb"); // dbg!("before pb");
// future to init work with pub sub mechanism // future to init work with pub sub mechanism
let pubsub_future = tokio::spawn(async move { let pubsub_future = tokio::spawn(async move {
let _ = pubsub_config_reciever( pubsub_config_reciever(
tx_pb_lc, tx_pb_lc,
params.clone(), params.clone(),
local_config_brd_reciever local_config_brd_reciever
).await; ).await
}); });
// dbg!("before cli"); // dbg!("before cli");
@ -71,15 +76,68 @@ pub mod v2 {
from_cli_config_reciever( from_cli_config_reciever(
cli_oneshot, cli_oneshot,
tx_cli_lc tx_cli_lc
).await; ).await
}); });
// let _ = lc_future.await; // let _ = lc_future.await;
// dbg!("before select"); // dbg!("before select");
tokio::select! { tokio::select! {
lc_result = lc_future => {dbg!("end of lc");}, lc_result = lc_future => {
pb_result = pubsub_future => {dbg!("end of pb");}, // dbg!("end of lc");
cli_config_option = cli_future => {dbg!("end of cli");}, 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"); // dbg!("after select");
// TODO! futures + select! [OK] // TODO! futures + select! [OK]