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::*;
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>> {
let config_path = params.config.to_str().unwrap_or_else(|| "settings.json");
if params.no_sub || params.no_sub {
// let config_path = params.config.to_str().unwrap_or_else(|| "settings.json");
if params.no_sub {
return None;
}
if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) {
if let Ok(mut conn) = client.get_connection() {
match crate::utils::get_container_id() {
Some(channel_name) => {
let channel_name = channel_name.trim();
let mut pubsub = conn.as_pubsub();
if pubsub.subscribe(&channel_name).is_ok() {
let mut connection_delay: u64 = 1;
loop {
if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) {
if let Ok(mut conn) = client.get_connection() {
match crate::utils::get_container_id() {
Some(channel_name) => {
// let channel_name = channel_name.trim();
let mut pubsub = conn.as_pubsub();
if pubsub.subscribe(&channel_name.trim()).is_ok() {
} else {
error!("Cannot subscribe channel {}. Check Redis Server status", &channel_name);
todo!()
} 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
}
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> {
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);
}
if let Ok(client) = Client::open(format!("redis://{}/", &params.remote_server_url)) {