use crate::daemon::Daemon;
use std::sync::Arc;
use std::time::Duration;
fn sweep_secs() -> u64 {
std::env::var("AUTOFORK_LIVENESS_SWEEP_SECS")
.ok()
.and_then(|v| v.parse().ok())
.filter(|&s| s > 0)
.unwrap_or(15)
}
pub async fn harness_reaper(daemon: Arc<Daemon>) {
let period = Duration::from_secs(sweep_secs());
loop {
tokio::select! {
_ = daemon.shutdown.notified() => return,
_ = tokio::time::sleep(period) => {}
}
for (sid, last_activity) in daemon.dead_harness_sessions() {
let inherited = last_activity < daemon.started_at;
tracing::info!(session = %sid, inherited,
"client process gone, closing session");
daemon.close_session_with_flush(&sid, "gone", !inherited);
}
}
}