diff --git a/README.md b/README.md index 79fd58b..c8897c7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,6 @@ | Crate (submodule) | Progress | |---|---| |`api-grub` | ✅✅✅✅✅✅✅🔲🔲🔲 | -|`config-delivery` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 | +|`config-delivery` | ✅✅✅✅🔲🔲🔲🔲🔲🔲 | |`integrs-structs` | ✅✅✅✅✅✅🔲🔲🔲🔲 | |`preproc` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 | diff --git a/crates/config-delivery/src/delivery.rs b/crates/config-delivery/src/delivery.rs index e69de29..38afe4b 100644 --- a/crates/config-delivery/src/delivery.rs +++ b/crates/config-delivery/src/delivery.rs @@ -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 { + 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); } + // +} \ No newline at end of file diff --git a/crates/config-delivery/src/main.rs b/crates/config-delivery/src/main.rs index cb36659..2be1247 100644 --- a/crates/config-delivery/src/main.rs +++ b/crates/config-delivery/src/main.rs @@ -1,6 +1,24 @@ mod delivery; mod integration; +mod logger; -fn main() { +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(()) }