From 3f98fd7f24e168298686e4ee2c898a74fd6fa740 Mon Sep 17 00:00:00 2001 From: prplV Date: Fri, 23 May 2025 16:16:03 +0300 Subject: [PATCH] prcs update --- noxis-rs/src/options/cli_pipeline.rs | 2 +- noxis-rs/src/utils/prcs.rs | 44 +++++++++++++++++++--------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/noxis-rs/src/options/cli_pipeline.rs b/noxis-rs/src/options/cli_pipeline.rs index f711ac9..a976a19 100644 --- a/noxis-rs/src/options/cli_pipeline.rs +++ b/noxis-rs/src/options/cli_pipeline.rs @@ -167,7 +167,7 @@ async fn process_cli_cmd(cli : Cli, params: Arc, global_config : }, ConfigAction::Remote => {Ok(params.remote_server_url.clone())}, /* */ - _ => Err(anyhow::Error::msg("Unrecognized command from CLI")) + // _ => Err(anyhow::Error::msg("Unrecognized command from CLI")) } }, /* */ diff --git a/noxis-rs/src/utils/prcs.rs b/noxis-rs/src/utils/prcs.rs index 76a09f6..4ed600b 100644 --- a/noxis-rs/src/utils/prcs.rs +++ b/noxis-rs/src/utils/prcs.rs @@ -10,6 +10,7 @@ use serde::Serialize; pub mod v2 { use log::info; + use tokio::time::sleep; use crate::options::structs::DependencyType; use std::path::Path; @@ -119,6 +120,7 @@ pub mod v2 { "restart" => { info!("Event on {} `{}` for {}. Restarting ...", dep_type, dep_name, self.name); let _ = restart_process(&self.name, &self.bin).await; + sleep(Duration::from_millis(100)).await; self.pid = Pid::new_from_output(get_pid(self.name.as_ref()).await); info!("{}: New PID - {}", self.name, self.pid); }, @@ -126,6 +128,26 @@ pub mod v2 { } tokio::time::sleep(Duration::from_micros(100)).await; } + pub async fn stop_by_user_call(&mut self) -> anyhow::Result<()> { + terminate_process(&self.name).await?; + self.state = ProcessState::StoppedByCli; + Ok(()) + } + pub async fn freeze_by_user_call(&mut self) -> anyhow::Result<()> { + freeze_process(&self.name).await?; + self.state = ProcessState::HoldingByCli; + Ok(()) + } + pub async fn start_by_user_call(&mut self) -> anyhow::Result<()> { + start_process(&self.name, &self.bin).await?; + self.state = ProcessState::Pending; + Ok(()) + } + pub async fn unfreeze_by_user_call(&mut self) -> anyhow::Result<()> { + unfreeze_process(&self.name).await?; + self.state = ProcessState::Pending; + Ok(()) + } } #[async_trait] @@ -298,14 +320,11 @@ pub async fn is_frozen(name: &str) -> bool { /// /// *depends on* : - /// -pub async fn terminate_process(name: &str) { +pub async fn terminate_process(name: &str) -> anyhow::Result<()> { let _ = Command::new("pkill") - .arg(name) - .output() - .unwrap_or_else(|_| { - error!("Failed to execute command 'pkill'"); - std::process::exit(101); - }); + .arg(name) + .output()?; + Ok(()) } /// # Fn `terminate_process` @@ -321,14 +340,11 @@ pub async fn terminate_process(name: &str) { /// /// *depends on* : - /// -pub async fn freeze_process(name: &str) { +pub async fn freeze_process(name: &str) -> anyhow::Result<()> { let _ = Command::new("pkill") .args(["-STOP", name]) - .output() - .unwrap_or_else(|_| { - error!("Failed to freeze process"); - std::process::exit(101); - }); + .output()?; + Ok(()) } /// # Fn `unfreeze_process` @@ -365,7 +381,7 @@ pub async fn unfreeze_process(name: &str) -> anyhow::Result<()> { /// *depends on* : fn `start_process`, fn `terminate_process` /// pub async fn restart_process(name: &str, path: &str) -> anyhow::Result<()> { - terminate_process(name).await; + terminate_process(name).await?; tokio::time::sleep(Duration::from_millis(100)).await; start_process(name, path).await }