Add detailed logging to process holder

This commit is contained in:
Félix Saparelli 2022-01-31 00:05:10 +13:00
parent 9a736c5eb9
commit 2a9ee4de0b
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,7 @@
use std::sync::Arc;
use tokio::sync::RwLock;
use tracing::trace;
use crate::{command::Supervisor, error::RuntimeError, signal::process::SubSignal};
@ -21,31 +22,50 @@ impl ProcessHolder {
}
pub async fn drop_inner(&self) {
trace!("dropping supervisor");
self.0.write().await.take();
trace!("dropped supervisor");
}
pub async fn replace(&self, new: Supervisor) {
trace!("replacing supervisor");
if let Some(_old) = self.0.write().await.replace(new) {
trace!("replaced supervisor");
// TODO: figure out what to do with old
} else {
trace!("not replaced: no supervisor");
}
}
pub async fn signal(&self, sig: SubSignal) {
if let Some(p) = self.0.read().await.as_ref() {
trace!("signaling supervisor");
p.signal(sig).await;
trace!("signaled supervisor");
} else {
trace!("not signaling: no supervisor");
}
}
pub async fn kill(&self) {
if let Some(p) = self.0.read().await.as_ref() {
trace!("killing supervisor");
p.kill().await;
trace!("killed supervisor");
} else {
trace!("not killing: no supervisor");
}
}
pub async fn wait(&self) -> Result<(), RuntimeError> {
if let Some(p) = self.0.read().await.as_ref() {
trace!("waiting on supervisor");
p.wait().await?;
trace!("waited on supervisor");
} else {
trace!("not waiting: no supervisor");
}
Ok(())
Ok(())
}
}