fixed all config error and questions
parent
9fb57ba3a7
commit
535398e58a
|
|
@ -618,7 +618,7 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "runner-rs"
|
name = "runner-rs"
|
||||||
version = "0.9.24"
|
version = "0.9.25"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "runner-rs"
|
name = "runner-rs"
|
||||||
version = "0.9.24"
|
version = "0.9.25"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::options::structs::*;
|
use crate::options::structs::*;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use redis::{Client, Commands, Connection, RedisResult};
|
use redis::{Client, Connection};
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
|
|
@ -11,7 +11,6 @@ use tokio::time::Duration;
|
||||||
|
|
||||||
const CONFIG_PATH: &str = "settings.json";
|
const CONFIG_PATH: &str = "settings.json";
|
||||||
|
|
||||||
type Res = RedisResult<Vec<Vec<(String, Vec<(String, String)>)>>>;
|
|
||||||
// 4ever sync
|
// 4ever sync
|
||||||
fn load_processes(json_filename: &str) -> Option<Processes> {
|
fn load_processes(json_filename: &str) -> Option<Processes> {
|
||||||
if let Ok(res) = fs::read_to_string(json_filename) {
|
if let Ok(res) = fs::read_to_string(json_filename) {
|
||||||
|
|
@ -109,49 +108,46 @@ async fn get_remote_conf_watcher(conn : &mut Connection) -> Option<Processes> {
|
||||||
// ! once iter exec
|
// ! once iter exec
|
||||||
// ! only for situation when local isn't None (no need to fck redis server)
|
// ! only for situation when local isn't None (no need to fck redis server)
|
||||||
fn once_get_remote_configuration(serv_info: &str) -> Option<Processes> {
|
fn once_get_remote_configuration(serv_info: &str) -> Option<Processes> {
|
||||||
|
let cont = crate::utils::get_container_id();
|
||||||
match Client::open(serv_info) {
|
match Client::open(serv_info) {
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
match client.get_connection() {
|
match client.get_connection() {
|
||||||
Ok(mut conn) => {
|
Ok(mut conn) => {
|
||||||
if let Ok(len) = conn.xlen::<&str, usize>("config_stream") {
|
let mut conn = conn.as_pubsub();
|
||||||
if len == 0 {
|
match conn.subscribe(cont) {
|
||||||
warn!("No configuration in DB yet");
|
Ok(_) => {
|
||||||
None
|
if conn.set_read_timeout(Some(Duration::from_millis(100))).is_err() {
|
||||||
} else {
|
error!("Cannot set reading pubsub timeout and pull remote config");
|
||||||
let conf: Res = conn.xrevrange_count("config_stream", "+", "-", 1);
|
return None;
|
||||||
let config: &Vec<(String, Vec<(String, String)>)>;
|
|
||||||
|
|
||||||
if conf.is_ok() {
|
|
||||||
// guaranteed and safe unwrapping
|
|
||||||
let conf = conf.unwrap();
|
|
||||||
config = &conf[0];
|
|
||||||
if config.is_empty() {
|
|
||||||
error!(
|
|
||||||
"Empty config was pulled. Check stream and configs state!"
|
|
||||||
);
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
match parse_extern_config(&config[0].1[0].1) {
|
|
||||||
Some(prcs) => {
|
|
||||||
info!(
|
|
||||||
"Config {} was pulled from Redis-Server",
|
|
||||||
&prcs.date_of_creation
|
|
||||||
);
|
|
||||||
Some(prcs)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
error!("Invalid configuration was pulled (PARSING_ERROR). Check configs state!");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error!("Configuration pulling from Redis stream failed. Check stream state!");
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
match conn.get_message() {
|
||||||
|
Ok(msg) => {
|
||||||
|
info!("Pulled config from Redis Server");
|
||||||
|
let get_payload: Result<String, redis::RedisError> = msg.get_payload();
|
||||||
|
match get_payload {
|
||||||
|
Ok(payload) => {
|
||||||
|
let remote = parse_extern_config(&payload);
|
||||||
|
if remote.is_none() {
|
||||||
|
error!("Pulled config is invalid. Check it in Redis Server");
|
||||||
|
}
|
||||||
|
return remote;
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
error!("Cannot extract payload from new message. Check Redis Server state");
|
||||||
|
return None;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
warn!("Cannot get config from Redis Server. Empty channel");
|
||||||
|
return None;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
error!("Redis subscription process failed. Check Redis configuration!");
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
error!("Cannot find config_stream. Check Redis-stream accessibility!");
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
// module needed to check host-agent health condition and to communicate with it
|
// module needed to check host-agent health condition and to communicate with it
|
||||||
|
/// asdasdasds
|
||||||
use tokio::{io::Interest, net::UnixStream};
|
use tokio::{io::Interest, net::UnixStream};
|
||||||
//
|
|
||||||
// code will be here
|
|
||||||
//
|
|
||||||
async fn open_unix_socket() -> Result<UnixStream, std::io::Error> {
|
async fn open_unix_socket() -> Result<UnixStream, std::io::Error> {
|
||||||
let socket = UnixStream::connect("/var/run/enode/hostagent.sock").await?;
|
let socket = UnixStream::connect("/var/run/enode/hostagent.sock").await?;
|
||||||
Ok(socket)
|
Ok(socket)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue