Share lifecycle helpers for node processes

This commit is contained in:
andrussal 2025-12-10 13:38:37 +01:00
parent f6e6244226
commit 4daf3e3e12
6 changed files with 31 additions and 12 deletions

View File

@ -0,0 +1,8 @@
#![allow(dead_code)]
use std::process::Child;
/// Shared cleanup helpers for child processes.
pub fn kill_child(child: &mut Child) {
let _ = child.kill();
}

View File

@ -0,0 +1,8 @@
#![allow(dead_code)]
use std::process::Child;
/// Shared lifecycle hooks (placeholder).
pub fn kill_child(child: &mut Child) {
let _ = child.kill();
}

View File

@ -1,3 +1,4 @@
pub mod cleanup;
pub mod kill;
pub mod monitor;
pub mod spawn;

View File

@ -1,4 +1,11 @@
#![allow(dead_code)]
/// Shared monitoring helpers (placeholder).
pub struct Monitor;
use std::process::Child;
/// Check if a child process is still running.
pub fn is_running(child: &mut Child) -> bool {
match child.try_wait() {
Ok(None) => true,
Ok(Some(_)) | Err(_) => false,
}
}

View File

@ -31,6 +31,7 @@ use crate::{
common::{
binary::{BinaryConfig, BinaryResolver},
config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths},
lifecycle::kill::kill_child,
},
},
};
@ -62,9 +63,7 @@ impl Drop for Executor {
println!("failed to persist tempdir: {e}");
}
if let Err(e) = self.child.kill() {
println!("failed to kill the child process: {e}");
}
kill_child(&mut self.child);
}
}

View File

@ -30,6 +30,7 @@ use crate::{
common::{
binary::{BinaryConfig, BinaryResolver},
config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths},
lifecycle::kill::kill_child,
},
},
};
@ -66,19 +67,14 @@ impl Drop for Validator {
println!("failed to persist tempdir: {e}");
}
if let Err(e) = self.child.kill() {
println!("failed to kill the child process: {e}");
}
kill_child(&mut self.child);
}
}
impl Validator {
/// Check if the validator process is still running
pub fn is_running(&mut self) -> bool {
match self.child.try_wait() {
Ok(None) => true,
Ok(Some(_)) | Err(_) => false,
}
crate::nodes::common::lifecycle::monitor::is_running(&mut self.child)
}
/// Wait for the validator process to exit, with a timeout