sending signal to dead reader fixed

pull/9/head
prplV 2024-09-23 11:06:53 +03:00
parent 29d517e66e
commit 0ab30aaee3
6 changed files with 31 additions and 24 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
.idea
Dockerfile
Cargo.lock

View File

@ -1,5 +1,5 @@
{
"dateOfCreation": "1721381809101",
"dateOfCreation": "1721381809103",
"processes": [
{
"name": "web-server",
@ -30,7 +30,7 @@
"triggers": {
"wait": 6,
"delay": 1,
"onLost": "stop"
"onLost": "hold"
}
}
]
@ -46,7 +46,7 @@
"src": "/home/vladislav/web/",
"triggers": {
"onDelete": "hold",
"onChange": "restart"
"onChange": "stop"
}
}
],
@ -57,7 +57,7 @@
"triggers": {
"wait": 5,
"delay": 1,
"onLost": "stop"
"onLost": "hold"
}
},
{
@ -66,7 +66,7 @@
"triggers": {
"wait": 6,
"delay": 2,
"onLost": "hold"
"onLost": "stop"
}
}
]

View File

@ -38,6 +38,7 @@ pub async fn file_handler(
}
"stop" => {
if is_active(name).await {
// todo: new signal and full termination
tx.send(1).await.unwrap();
}
return Err(CustomError::Fatal);

View File

@ -16,6 +16,8 @@ pub async fn service_handler(
if check_service(&serv.hostname, &serv.port).await.is_err() {
if !is_active(name).await || is_frozen(name).await {
return Err(CustomError::Fatal);
} else {
println!("{} is active and non-frozen", name);
}
error!(
"Service {}:{} is unreachable for process {}",
@ -26,7 +28,7 @@ pub async fn service_handler(
"stop" => {
if looped_service_connecting(name, serv).await.is_err() {
tx.send(5).await.unwrap();
tokio::time::sleep(Duration::from_millis(400)).await;
tokio::task::yield_now().await;
return Err(CustomError::Fatal);
}
}
@ -36,7 +38,7 @@ pub async fn service_handler(
// }
if looped_service_connecting(name, serv).await.is_err() {
tx.send(6).await.unwrap();
tokio::time::sleep(Duration::from_millis(400)).await;
tokio::task::yield_now().await;
return Err(CustomError::Fatal);
}
}
@ -48,12 +50,10 @@ pub async fn service_handler(
}
}
tokio::time::sleep(Duration::from_millis(100)).await;
tokio::task::yield_now().await;
Ok(())
}
async fn looped_service_connecting(name: &str, serv: &Services) -> Result<(), CustomError> {
let mut counter = 0;
if serv.triggers.wait == 0 {
loop {
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
@ -80,9 +80,8 @@ async fn looped_service_connecting(name: &str, serv: &Services) -> Result<(), Cu
let start = Instant::now();
while start.elapsed().as_secs() < serv.triggers.wait.into() {
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
counter += 1;
warn!(
"{counter} Attempting to connect from {} process to {}:{}",
"Attempting to connect from {} process to {}:{}",
&name, &serv.hostname, &serv.port
);
match check_service(&serv.hostname, &serv.port).await {

View File

@ -69,7 +69,7 @@ impl SigPostProcessing for Sig {
if let Some(_) = self.signal.recv().await {
log::info!("Got {} signal", self.sig_type);
for prc in self.senders.clone().iter() {
prc.send(111).await.unwrap();
let _ = prc.send(111).await;
}
}
Ok(())

View File

@ -32,7 +32,6 @@ pub async fn run_daemons(
}
let watchers_clone: Arc<tokio::sync::Mutex<Vec<Inotify>>> =
Arc::new(tokio::sync::Mutex::new(watchers));
loop {
let run_hand = running_handler(proc.clone(), tx.clone(), watchers_clone.clone());
tokio::select! {
@ -46,7 +45,7 @@ pub async fn run_daemons(
terminate_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
}
// break;
return;
},
// 2 - File-dependency handling error -> holding (after waiting)
2 => {
@ -59,10 +58,12 @@ pub async fn run_daemons(
// 3 - Running process error
3 => {
error!("Error due to starting {} process", &proc.name);
break;
},
// 4 - Timeout of waiting service-dependency -> staying (after waiting)
4 => {
warn!("Timeout of waiting service-dependency: Ignoring on {} process ..." , &proc.name);
tokio::time::sleep(Duration::from_millis(100)).await;
},
// 5 - Timeout of waiting service-dependency -> terminating (after waiting)
5 => {
@ -86,6 +87,7 @@ pub async fn run_daemons(
error!("File-dependency warning (file changed). Terminating {} process...", &proc.name);
terminate_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
return;
},
// // 8 - File-dependency change -> restarting (after check)
8 => {
@ -96,22 +98,25 @@ pub async fn run_daemons(
// // 9 - File-dependency change -> staying (after check)
9 => {
warn!("File-dependency warning (file changed). Ignoring event on {} process...", &proc.name);
tokio::time::sleep(Duration::from_millis(100)).await;
},
// 10 - Process unfreaze call via file handler
10 => {
// 10 - Process unfreaze call via file handler (or service handler)
10 | 11 => {
if is_frozen(&proc.name).await {
warn!("Unfreezing process {} call...", &proc.name);
unfreeze_process(&proc.name).await;
}
tokio::time::sleep(Duration::from_millis(100)).await;
},
// 11 - Process unfreaze call via service handler
11 => {
if is_frozen(&proc.name).await {
warn!("Unfreezing process {} call...", &proc.name);
unfreeze_process(&proc.name).await;
}
},
// 11 => {
// if is_frozen(&proc.name).await {
// warn!("Unfreezing process {} call...", &proc.name);
// unfreeze_process(&proc.name).await;
// }
// tokio::time::sleep(Duration::from_millis(100)).await;
// },
// 101 - Impermissible trigger values in JSON
101 => {
error!("Impermissible trigger values in JSON");
@ -138,8 +143,9 @@ pub async fn run_daemons(
}
},
}
// tokio::task::yield_now().await;
tokio::task::yield_now().await;
}
tokio::task::yield_now().await;
}
// check process status daemon
pub async fn running_handler(