Compare commits

..

4 Commits

Author SHA1 Message Date
prplV 48d39addf0 config: delivery update 2025-01-17 15:30:02 +03:00
prplV 52cba47abe temp env file for clarity 2025-01-17 15:26:27 +03:00
prplV 9b8e27524b config: logger added 2025-01-17 15:25:47 +03:00
prplV 124fbbeb7d setting up for config-delivery mod dev 2025-01-17 14:02:59 +03:00
7 changed files with 131 additions and 3 deletions

3
.env Normal file
View File

@ -0,0 +1,3 @@
CONFIG_SERVER_CREDS = "ws://127.0.0.1:8080"
API_GRUBBER_SOCKET = "api-grub.sock"
PREPROC_SOCKET = "preproc.sock"

View File

@ -10,6 +10,6 @@
| Crate (submodule) | Progress |
|---|---|
|`api-grub` | ✅✅✅✅✅✅✅🔲🔲🔲 |
|`config-delivery` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |
|`config-delivery` | ✅✅✅✅🔲🔲🔲🔲🔲🔲 |
|`integrs-structs` | ✅✅✅✅✅✅🔲🔲🔲🔲 |
|`preproc` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |

View File

@ -1,6 +1,17 @@
[package]
name = "config-delivery"
version = "0.1.0"
version = "0.3.4"
edition = "2021"
[dependencies]
dotenv = "0.15.0"
rand = "0.8.5"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
tokio = { version = "1.43.0", features = ["full"] }
tokio-websockets = { version = "^0.11.0", features = ["client", "openssl", "rand"] }
integr-structs = {path = "../integr-structs"}
anyhow = "1.0.95"
env_logger = "0.11.6"
log = "0.4.25"
chrono = "0.4.39"

View File

@ -0,0 +1,43 @@
// mod to communicate with api-grub and preproc services
// using Unix-Socket Client
use anyhow::{Error, Result};
use integr_structs::api::ApiConfig;
use tokio::time::{sleep, Instant};
use tokio::net::UnixStream;
use std::env;
enum UnixSocketConsumer {
ApiGrubber,
Preproc,
}
// to create us-client
struct UnixSocketClient;
impl UnixSocketConsumer {
pub async fn get_stream_object(&self) -> Result<UnixStream> {
let socket_file = match self {
UnixSocketConsumer::ApiGrubber => env::var("API_GRUBBER_SOCKET")?,
UnixSocketConsumer::Preproc => env::var("PREPROC_SOCKET")?,
};
UnixStream::connect(socket_file).await.or_else(|_| Err(Error::msg("Cannot create Unix-Socket client")))
}
}
async fn check_unix_socket_file(path: &str) -> bool {
std::path::Path::new(path).exists()
}
#[cfg(tests)]
mod delivery_unittests {
use super::*;
use tokio::test;
//
#[test]
async fn check_api_unix_socket_client_creation() { assert!(true); }
#[test]
async fn check_preproc_unix_socket_client_creation() { assert!(true); }
//
}

View File

@ -0,0 +1,50 @@
use chrono::Local;
use env_logger::Builder;
use log::LevelFilter;
use std::io::Write;
use anyhow::Result;
use log::info;
pub async fn setup_logger() -> Result<()> {
Builder::new()
.format(move |buf, record| {
writeln!(
buf,
"|{}| {} [{}] - {}",
"config-delivery",
Local::now().format("%d-%m-%Y %H:%M:%S"),
record.level(),
record.args(),
)
})
.filter(None, LevelFilter::Info)
.target(env_logger::Target::Stdout)
.init();
info!("Logger configured");
Ok(())
}
#[cfg(test)]
mod logger_unittests {
use tokio::test;
use super::*;
#[test]
async fn check_logger_builder() {
Builder::new()
.format(move |buf, record| {
writeln!(
buf,
"|{}| {} [{}] - {}",
"config-delivery",
Local::now().format("%d-%m-%Y %H:%M:%S"),
record.level(),
record.args(),
)
})
.filter(None, LevelFilter::Info)
.target(env_logger::Target::Stdout)
.init();
}
}

View File

@ -1,3 +1,24 @@
fn main() {
mod delivery;
mod integration;
mod logger;
use logger::setup_logger;
use dotenv::dotenv;
use anyhow::Result;
use tokio::sync::mpsc;
use log::info;
// Arch :
// 1) 2 Unix-Socket client (for api grub and preproc) :: i think its a continious process for events when services are unavailable
// 2) mpsc beetween `delivery` and `integration` ::
// 3) websocket client in `integration` to pull configs from Monitoring System ::
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()> {
let _ = setup_logger().await?;
dotenv().ok();
info!("Pulling env vars from .env file if exists ...");
println!("Hello, world!");
Ok(())
}