pull/9/head
prplV 2024-11-06 11:57:35 +03:00
parent 27c21e5cd9
commit 52431ffd6f
2 changed files with 10 additions and 10 deletions

View File

@ -32,7 +32,7 @@ mod metrics_unittets {
assert!(true);
}
#[tokio::test]
async fn init_sumodules() {
async fn get_metrics_grubber() {
assert!(true);
}
// Option<Vec<TrackingProcess OR String>> output

View File

@ -5,18 +5,19 @@ use std::process::{Command, Output};
use std::sync::Arc;
use tokio::time::Duration;
pub async fn get_pid(name: &str) -> Result<Output, std::io::Error> {
pub async fn get_pid(name: &str) -> Option<Output> {
let name = Arc::new(name.to_string());
let res =
tokio::task::spawn_blocking(move || Command::new("pidof").arg(&*name).output()).await?;
// todo : unwrap change - can be unsafe
tokio::task::spawn_blocking(move || Command::new("pidof").arg(&*name).output()).await.unwrap();
if let Ok(output) = res {
if output.stderr.is_empty() && output.stdout.is_empty() {
return Err(io::ErrorKind::NotFound.into());
None
} else {
Ok(output)
Some(output)
}
} else {
return Err(io::ErrorKind::NotFound.into());
None
}
}
// ! can be with bug !!!
@ -40,7 +41,7 @@ pub async fn is_active(name: &str) -> bool {
// T is for stopped processes
pub async fn is_frozen(name: &str) -> bool {
let temp: Output;
if let Ok(output) = get_pid(name).await {
if let Some(output) = get_pid(name).await {
temp = output;
} else {
return false;
@ -128,7 +129,6 @@ mod process_unittests {
// rewrite, its a pipe
#[tokio::test]
async fn full_cycle_with_restart() {
assert!(true);
let res1 = start_process("temp-process", "/home/user/monitor/runner-rs/temp-process").await;
assert!(res1.is_ok());
let res2 =
@ -157,12 +157,12 @@ mod process_unittests {
}
#[tokio::test]
async fn pidof_active_process() {
assert!(get_pid("systemd").await.is_ok());
assert!(get_pid("systemd").await.is_some());
}
// broken mechanism need to check
#[tokio::test]
async fn pidof_disabled_process() {
assert!(get_pid("invalid-process-name").await.is_err());
assert!(get_pid("invalid-process-name").await.is_none());
}
}