From 08e99385b91673266f3574a4871485ebc6e87cf8 Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 29 May 2025 16:59:12 +0300 Subject: [PATCH] force stop and freeze wrapping --- noxis-rs/src/utils/prcs.rs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/noxis-rs/src/utils/prcs.rs b/noxis-rs/src/utils/prcs.rs index 3214edd..4747204 100644 --- a/noxis-rs/src/utils/prcs.rs +++ b/noxis-rs/src/utils/prcs.rs @@ -191,20 +191,20 @@ pub mod v2 { impl ProcessUnit for ProcessesController { async fn process(&mut self) { if self.negative_events.len() == 0 { - match self.state { - ProcessState::Holding => { - info!("No negative dependecies events on {} process. Unfreezing ...", self.name); + let conditions = (is_active(&self.name).await, is_frozen(&self.name).await); + let state = &self.state; + match (state, conditions) { + (ProcessState::Holding, (_, _)) => { + info!("No negative dependecies events on {} frozen process. Unfreezing ...", self.name); if let Err(er) = unfreeze_process(&self.name).await { error!("Cannot unfreeze process {} : {}", self.name, er); } else { self.state = ProcessState::Pending; - // self.pid = Pid::new_from_output(get_pid(self.name.as_ref()).await); - // info!("{}: New PID - {}", self.name, self.pid); info!("Process {} was unfreezed", &self.name); } }, - ProcessState::Stopped => { - info!("No negative dependecies events on {} process. Starting ...", self.name); + (ProcessState::Stopped, (_, _)) => { + info!("No negative dependecies events on stopped {} process. Starting ...", self.name); match start_process(&self.name, &self.bin).await { Ok(pid) => { self.state = ProcessState::Pending; @@ -216,6 +216,28 @@ pub mod v2 { }, } }, + (ProcessState::Pending, (false, false)) => { + info!("{} process was impermissibly stopped. Starting ...", self.name); + match start_process(&self.name, &self.bin).await { + Ok(pid) => { + self.state = ProcessState::Pending; + self.pid = Pid(pid); + info!("{}: New PID - {}", self.name, self.pid); + }, + Err(er) => { + error!("Cannot start process {} : {}", self.name, er); + }, + } + }, + (ProcessState::Pending, (true, true)) => { + info!("No negative dependecies events on {} process. Unfreezing ...", self.name); + if let Err(er) = unfreeze_process(&self.name).await { + error!("Cannot unfreeze process {} : {}", self.name, er); + } else { + self.state = ProcessState::Pending; + info!("Process {} was unfreezed", &self.name); + } + }, _ => {}, } }