From 40b0ba9e6e4f7eca430f2a7237754cbeaab14e54 Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 3 Oct 2024 15:14:17 +0300 Subject: [PATCH] config server now in settings.json --- settings.json | 1 + src/config.rs | 7 ++++--- src/structs.rs | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/settings.json b/settings.json index 9f23132..90f3631 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,6 @@ { "dateOfCreation": "1721381809103", + "configServer" : "localhost", "processes": [ { "name": "web-server", diff --git a/src/config.rs b/src/config.rs index e1d3459..b3b6132 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,6 +5,7 @@ use std::os::unix::process::CommandExt; use std::process::Command; use std::sync::Arc; use std::{env, fs}; +use std::fmt::format; use tokio::time::Duration; const CONFIG_PATH: &str = "settings.json"; @@ -29,7 +30,7 @@ pub fn get_actual_config() -> Option { "Found local configuration, version - {}", &local_conf.date_of_creation ); - if let Some(remote_conf) = once_get_remote_configuration("redis://172.19.32.198:6379/") { + if let Some(remote_conf) = once_get_remote_configuration(&format!("redis://{}/", local_conf.config_server)) { return match config_comparing(&local_conf, &remote_conf) { ConfigActuality::Local => { info!("Local config is actual"); @@ -48,7 +49,7 @@ pub fn get_actual_config() -> Option { } None => { // ? ? OUTSTANDING CONSTRUCTION ? - let mut conn = get_connection_watcher(&open_watcher("redis://localhost")); + let mut conn = get_connection_watcher(&open_watcher("redis://localhost/")); get_stream_info_watcher(&mut conn); let remote_config = invalid_config_watcher(&mut conn); let _ = save_new_config(&remote_config, CONFIG_PATH); @@ -195,7 +196,7 @@ fn restart_main_thread() -> std::io::Result<()> { Ok(()) } pub async fn subscribe_config_stream(actual_prcs: Arc) -> Result<(), CustomError> { - if let Ok(client) = Client::open("redis://localhost") { + if let Ok(client) = Client::open(format!("redis://{}/", &actual_prcs.config_server)) { if let Ok(mut conn) = client.get_connection() { info!("Runner subscribed on config update"); loop { diff --git a/src/structs.rs b/src/structs.rs index 724dfc0..6838703 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -17,6 +17,8 @@ pub struct Processes { // runner_id: usize, #[serde(rename = "dateOfCreation")] pub date_of_creation: String, + #[serde(rename = "configServer")] + pub config_server: String, #[serde(default)] pub processes: Vec, }