patch is_frozen + logs + no comments

pull/9/head
prplV 2024-08-27 11:39:18 +03:00
parent 84d47813a2
commit 41f98bc850
3 changed files with 13 additions and 23 deletions

2
Cargo.lock generated
View File

@ -499,7 +499,7 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]] [[package]]
name = "runner-rs" name = "runner-rs"
version = "0.5.0" version = "0.5.1"
dependencies = [ dependencies = [
"chrono", "chrono",
"env_logger", "env_logger",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "runner-rs" name = "runner-rs"
version = "0.5.0" version = "0.5.1"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -108,6 +108,7 @@ struct FIleTriggers {
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() { async fn main() {
// building logger with current output format // building logger with current output format
Builder::new() Builder::new()
.format(|buf, record|{ .format(|buf, record|{
@ -121,14 +122,17 @@ async fn main() {
.filter(None, LevelFilter::Info) .filter(None, LevelFilter::Info)
.init(); .init();
log::info!("Runner is configurating...");
// setting up redis connection \ // setting up redis connection \
// then conf checks to choose the most actual \ // then conf checks to choose the most actual \
let processes: Processes = get_actual_config().unwrap_or_else(|| { let processes: Processes = get_actual_config().unwrap_or_else(|| {
error!("No actual configuration for runner"); error!("No actual configuration for runner. Stopping...");
std::process::exit(101); std::process::exit(101);
}); });
log::info!("Current runner configuration: {}\n", &processes.date_of_creation); log::info!("Current runner configuration: {}", &processes.date_of_creation);
log::info!("Runner is ready. Initializing...");
if processes.processes.len() == 0 { if processes.processes.len() == 0 {
error!("Processes list is null, runner-rs initialization is stopped"); error!("Processes list is null, runner-rs initialization is stopped");
@ -353,23 +357,7 @@ async fn create_watcher(filename: &str, path: &str) -> Result<Inotify, std::io::
&src, &src,
WatchMask::ALL_EVENTS WatchMask::ALL_EVENTS
); );
// !
// // let _ = stream
// // .watches()
// // .add(
// // &src,
// // WatchMask::ALL_EVENTS
// // );
// while let Some(a) = stream.next().await {
// // println!("event - {:?}", a);
// if a.unwrap().mask == EventMask::MODIFY {
// counter+=1;
// println!("mod {} - {:?}", counter, stream);
// }
// }
// todo!();
// !
Ok(inotify) Ok(inotify)
} }
@ -542,6 +530,8 @@ async fn is_active(name: &str)-> bool {
.await .await
.unwrap() .unwrap()
} }
// T is for stopped processes
async fn is_frozen(name: &str) -> bool { async fn is_frozen(name: &str) -> bool {
let temp = get_pid(name).await; let temp = get_pid(name).await;
let pid = String::from_utf8_lossy(&temp.stdout); let pid = String::from_utf8_lossy(&temp.stdout);
@ -558,7 +548,7 @@ async fn is_frozen(name: &str) -> bool {
error!("Failed to execute ps command"); error!("Failed to execute ps command");
std::process::exit(101); std::process::exit(101);
}); });
!(String::from_utf8_lossy(&cmd.stdout) == "Sl+\n") String::from_utf8_lossy(&cmd.stdout).contains("T")
}) })
.await .await
.unwrap() .unwrap()