config pubsub pre-dev skeleton

feature/configv2
prplV 2025-02-03 13:58:01 +03:00
parent e9b6abefdf
commit df03bd5346
1 changed files with 24 additions and 17 deletions

View File

@ -18,30 +18,37 @@ pub mod v2 {
use super::*; use super::*;
pub async fn init_config_mechanism(cli_oneshot: Arc<Receiver<Processes>> /*...*/) { /* local + pubsub + cli oneshot check */ } pub async fn init_config_mechanism(cli_oneshot: Arc<Receiver<Processes>> /*...*/) { /* local + pubsub + cli oneshot check */ }
pub async fn get_pubsub<'a>(params: Arc<PrebootParams>) -> Option<PubSub<'a>> { pub async fn get_pubsub<'a>(params: Arc<PrebootParams>) -> Option<PubSub<'a>> {
let config_path = params.config.to_str().unwrap_or_else(|| "settings.json"); // let config_path = params.config.to_str().unwrap_or_else(|| "settings.json");
if params.no_sub {
if params.no_sub || params.no_sub {
return None; return None;
} }
if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) { let mut connection_delay: u64 = 1;
if let Ok(mut conn) = client.get_connection() { loop {
match crate::utils::get_container_id() { if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) {
Some(channel_name) => { if let Ok(mut conn) = client.get_connection() {
let channel_name = channel_name.trim(); match crate::utils::get_container_id() {
let mut pubsub = conn.as_pubsub(); Some(channel_name) => {
if pubsub.subscribe(&channel_name).is_ok() { // let channel_name = channel_name.trim();
let mut pubsub = conn.as_pubsub();
if pubsub.subscribe(&channel_name.trim()).is_ok() {
} else { todo!()
error!("Cannot subscribe channel {}. Check Redis Server status", &channel_name);
} else {
error!("Cannot subscribe channel {}. Check Redis Server status", &channel_name);
}
},
None => {
error!("Cannot get channel name");
} }
},
None => {
error!("Cannot get channel name");
} }
} }
} }
error!("Error with subscribing Redis stream on update. Retrying in {} secs...", connection_delay);
sleep(Duration::from_secs(connection_delay)).await;
connection_delay *= 2;
} }
error!("Error with subscribing Redis stream on update. Working only with selected config...");
None None
} }
pub async fn get_local_config_watcher(/*...*/) { /*...*/ } pub async fn get_local_config_watcher(/*...*/) { /*...*/ }
@ -360,7 +367,7 @@ fn restart_main_thread() -> std::io::Result<()> {
pub async fn subscribe_config_stream(actual_prcs: Arc<Processes>, params: Arc<PrebootParams>) -> Result<(), CustomError> { pub async fn subscribe_config_stream(actual_prcs: Arc<Processes>, params: Arc<PrebootParams>) -> Result<(), CustomError> {
let config_path = params.config.to_str().unwrap_or_else(|| "settings.json"); let config_path = params.config.to_str().unwrap_or_else(|| "settings.json");
if params.no_sub || params.no_sub { if params.no_sub {
return Err(CustomError::Fatal); return Err(CustomError::Fatal);
} }
if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) { if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) {