docs: signals
parent
e5437fb877
commit
a03fbc41b0
|
|
@ -9,6 +9,19 @@ use tokio::{
|
|||
|
||||
type SendersVec = Arc<Vec<Arc<mpsc::Sender<u8>>>>;
|
||||
|
||||
/// # Fn set_valid_destructor
|
||||
/// ## for initializing process of unstoppable grubbing metrics.
|
||||
///
|
||||
/// *input* : `Result<()>`
|
||||
///
|
||||
/// *output* : `Err` if it cant create signals listeners | `Ok` on returning Monitor
|
||||
///
|
||||
/// *initiator* : main thread
|
||||
///
|
||||
/// *managing* : `Arc<Vec<Arc<mpsc::Sender<u8>>>>`
|
||||
///
|
||||
/// *depends on* : Sig, Signals
|
||||
///
|
||||
pub async fn set_valid_destructor(senders: SendersVec) -> Result<(), CustomError> {
|
||||
let (mut int, mut term, mut stop) = (
|
||||
Sig::new(Signals::Sigint, senders.clone()),
|
||||
|
|
@ -23,16 +36,30 @@ pub async fn set_valid_destructor(senders: SendersVec) -> Result<(), CustomError
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
/// # Enum Signals
|
||||
/// ## for instancing each managed system signals (such as SIGINT)
|
||||
///
|
||||
/// > (element needed in Sig constructor's signature)
|
||||
///
|
||||
/// *depends on* : -
|
||||
enum Signals {
|
||||
Sigint,
|
||||
Sigterm,
|
||||
Sigstop,
|
||||
}
|
||||
|
||||
/// # Struct Signals
|
||||
/// ## for instancing each managed system signals (such as SIGINT)
|
||||
///
|
||||
/// > (needed to construct system signals listener)
|
||||
///
|
||||
/// *depends on* : Signals
|
||||
struct Sig {
|
||||
signal: Signal,
|
||||
sig_type: Signals,
|
||||
senders: SendersVec,
|
||||
}
|
||||
/// ## default Sig's constructor
|
||||
impl Sig {
|
||||
fn new(signal_type: Signals, sends: SendersVec) -> Self {
|
||||
Sig {
|
||||
|
|
@ -42,6 +69,9 @@ impl Sig {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// ## trait Display realization for returning String-name of signal
|
||||
///
|
||||
/// > (needed in logs)
|
||||
impl std::fmt::Display for Signals {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
@ -51,6 +81,7 @@ impl std::fmt::Display for Signals {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// ## associated func to init signals listener
|
||||
impl Signals {
|
||||
fn get_signal(&self) -> io::Result<Signal> {
|
||||
match self {
|
||||
|
|
@ -60,9 +91,20 @@ impl Signals {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// # Trait SigPostProcessing
|
||||
/// ## to handle post-processing jobs after getting system signal
|
||||
///
|
||||
/// ## > (needed in signals post-processing)
|
||||
///
|
||||
trait SigPostProcessing {
|
||||
async fn post_processing(&mut self) -> io::Result<()>;
|
||||
}
|
||||
|
||||
/// # Trait SigPostProcessing realization for Sig struct
|
||||
/// ## to deinitialize Monitor correctly after getting signal
|
||||
///
|
||||
/// ## > (needed in signals post-processing)
|
||||
///
|
||||
impl SigPostProcessing for Sig {
|
||||
async fn post_processing(&mut self) -> io::Result<()> {
|
||||
// manipulations ...
|
||||
|
|
|
|||
|
|
@ -17,15 +17,15 @@ use crate::utils::get_container_id;
|
|||
/// # Fn init_metrics_grubber
|
||||
/// ## for initializing process of unstoppable grubbing metrics.
|
||||
///
|
||||
/// `input` : vec of processes
|
||||
/// *input* : `Result<()>`
|
||||
///
|
||||
/// `output` : Err if it cant create grubbers | Ok on finish
|
||||
/// *output* : `Err` if it cant create grubbers | `Ok` on finish
|
||||
///
|
||||
/// `initiator` : main thread
|
||||
/// *initiator* : main thread
|
||||
///
|
||||
/// `managing` : object of unix-socket reader
|
||||
/// *managing* : object of unix-socket reader
|
||||
///
|
||||
/// `depends on` : network activity
|
||||
/// *depends on* : network activity
|
||||
///
|
||||
pub async fn init_metrics_grubber() {
|
||||
let mut system = System::new();
|
||||
|
|
|
|||
Loading…
Reference in New Issue