From 62af29b9e01e680791a4a4cb45f194da780ed5b6 Mon Sep 17 00:00:00 2001 From: prplV Date: Tue, 13 May 2025 11:32:30 +0300 Subject: [PATCH] added config storing in supervisor --- noxis-rs/src/utils.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/noxis-rs/src/utils.rs b/noxis-rs/src/utils.rs index b1e315a..03513db 100644 --- a/noxis-rs/src/utils.rs +++ b/noxis-rs/src/utils.rs @@ -12,7 +12,7 @@ use crate::options::structs::{CustomError, TrackingProcess, Processes}; // use inotify::Inotify; use log::{error, warn, info}; use prcs::{ - freeze_process, is_active, is_frozen, restart_process, start_process, terminate_process, + freeze_process, is_active, is_frozen, restart_process, terminate_process, unfreeze_process, }; // use services::service_handler; @@ -47,14 +47,16 @@ pub mod v2 { prcs : LinkedList, files : LinkedList, services : LinkedList, + config : Arc, } impl Supervisor { pub fn new() -> Supervisor { - Supervisor { prcs: LinkedList::new(), files: LinkedList::new(), services: LinkedList::new()} + Supervisor { prcs: LinkedList::new(), files: LinkedList::new(), services: LinkedList::new(), config: Arc::new(Processes::default()) } } - pub async fn with_config(mut self, config: &Processes) -> Supervisor { - let _ = config.processes.iter() + pub async fn with_config(mut self, config: Processes) -> Supervisor { + self.config = Arc::from(config); + let _ = self.config.processes.iter() .for_each(|prc| { let (rx, tx) = mpsc::channel::(10); let temp = ProcessesController::new(&prc.name, tx).with_exe(&prc.path); @@ -127,6 +129,9 @@ pub mod v2 { async fn process(&mut self) { info!("Initializing monitoring ..."); loop { + // + // todo: CHANNEL check and reaction + // // dbg!(&self); let mut tasks: Vec> = vec![]; // let (mut prc, mut file, mut serv) = (self.prcs.pop_front().unwrap(), self.files.pop_front().unwrap(), self.services.pop_front().unwrap()); @@ -177,7 +182,7 @@ pub mod v2 { pub async fn init_monitoring( config: Processes ) -> anyhow::Result<()> { - let mut supervisor = Supervisor::new().with_config(&config).await; + let mut supervisor = Supervisor::new().with_config(config).await; info!("Monitoring: {} ", &supervisor.get_stats()); supervisor.process().await; Ok(())