fixed blocking bug
parent
928c13ae11
commit
759ff64532
|
|
@ -57,8 +57,8 @@
|
|||
"hostname" : "localhost",
|
||||
"port" : 8080,
|
||||
"triggers" : {
|
||||
"wait" : 20,
|
||||
"delay" : 5,
|
||||
"wait" : 10,
|
||||
"delay" : 2,
|
||||
"onLost" : "stop"
|
||||
}
|
||||
}]
|
||||
|
|
|
|||
37
src/main.rs
37
src/main.rs
|
|
@ -1,6 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use tokio::io::Join;
|
||||
use tokio::join;
|
||||
use std::env::join_paths;
|
||||
use std::fmt::Debug;
|
||||
use std::fs;
|
||||
|
|
@ -108,14 +109,14 @@ async fn run_daemons(
|
|||
)
|
||||
{
|
||||
loop {
|
||||
let run_hand = running_handler(&proc.name, &proc.path, tx.clone());
|
||||
let file_hand = file_handler(&proc.name,&proc.dependencies.files, tx.clone());
|
||||
let serv_hand = service_handler(&proc.name, &proc.dependencies.services, tx.clone());
|
||||
let run_hand = running_handler(&proc, tx.clone());
|
||||
// let file_hand = file_handler(&proc.name,&proc.dependencies.files, tx.clone());
|
||||
// let serv_hand = service_handler(&proc.name, &proc.dependencies.services, tx.clone());
|
||||
|
||||
tokio::select! {
|
||||
_ = run_hand => {},
|
||||
_ = file_hand => {},
|
||||
_ = serv_hand => {},
|
||||
// _ = file_hand => {},
|
||||
// _ = serv_hand => {},
|
||||
_val = rx.recv() => {
|
||||
match _val.unwrap() {
|
||||
// 1 - File-dependency handling error -> terminating (after waiting)
|
||||
|
|
@ -246,26 +247,39 @@ async fn start_process(name: &str, path: &str) -> Result<(), CustomError> {
|
|||
}
|
||||
}
|
||||
// check process status daemon
|
||||
async fn running_handler(name: &str, path: &str, tx: mpsc::Sender<u8>){
|
||||
async fn running_handler(prc: &TrackingProcess, tx: mpsc::Sender<u8>){
|
||||
// println!("running daemon on {}", name);
|
||||
loop {
|
||||
let _ = Command::new("pidof")
|
||||
.arg(name)
|
||||
.arg(&prc.name)
|
||||
.output()
|
||||
.expect("Failed to execute command 'pidof'");
|
||||
// services and files check (once)
|
||||
// if inactive ->
|
||||
let files_check = file_handler(&prc.name, &prc.dependencies.files, tx.clone());
|
||||
let services_check = service_handler(&prc.name, &prc.dependencies.services, tx.clone());
|
||||
|
||||
if !is_active(name) && !is_frozen(name){
|
||||
if start_process(name, path).await.is_err() {
|
||||
join!(files_check, services_check);
|
||||
|
||||
// if inactive -> spawn checks -> active is true
|
||||
|
||||
if !is_active(&prc.name){
|
||||
if start_process(&prc.name, &prc.path).await.is_err() {
|
||||
tx.send(3).await.unwrap();
|
||||
// return;
|
||||
}
|
||||
}
|
||||
|
||||
// if frozen -> spawn checks -> unfreeze is true
|
||||
|
||||
else if is_frozen(&prc.name){
|
||||
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn file_handler(name: &str, files: &Vec<Files>, tx: mpsc::Sender<u8>) {
|
||||
loop {
|
||||
// println!("file daemon on {}", name);
|
||||
if is_active(name) && !is_frozen(name){
|
||||
for file in files {
|
||||
|
|
@ -301,7 +315,6 @@ async fn file_handler(name: &str, files: &Vec<Files>, tx: mpsc::Sender<u8>) {
|
|||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
}
|
||||
fn check_file(filename: &str, path: &str) -> Result<(), CustomError> {
|
||||
let fileconcat = format!("{}{}", path, filename);
|
||||
let path = Path::new(&fileconcat);
|
||||
|
|
|
|||
Loading…
Reference in New Issue