added config storing in supervisor
parent
b4c42dfc00
commit
62af29b9e0
|
|
@ -12,7 +12,7 @@ use crate::options::structs::{CustomError, TrackingProcess, Processes};
|
|||
// use inotify::Inotify;
|
||||
use log::{error, warn, info};
|
||||
use prcs::{
|
||||
freeze_process, is_active, is_frozen, restart_process, start_process, terminate_process,
|
||||
freeze_process, is_active, is_frozen, restart_process, terminate_process,
|
||||
unfreeze_process,
|
||||
};
|
||||
// use services::service_handler;
|
||||
|
|
@ -47,14 +47,16 @@ pub mod v2 {
|
|||
prcs : LinkedList<ProcessesController>,
|
||||
files : LinkedList<FilesController>,
|
||||
services : LinkedList<ServicesController>,
|
||||
config : Arc<Processes>,
|
||||
}
|
||||
|
||||
impl Supervisor {
|
||||
pub fn new() -> Supervisor {
|
||||
Supervisor { prcs: LinkedList::new(), files: LinkedList::new(), services: LinkedList::new()}
|
||||
Supervisor { prcs: LinkedList::new(), files: LinkedList::new(), services: LinkedList::new(), config: Arc::new(Processes::default()) }
|
||||
}
|
||||
pub async fn with_config(mut self, config: &Processes) -> Supervisor {
|
||||
let _ = config.processes.iter()
|
||||
pub async fn with_config(mut self, config: Processes) -> Supervisor {
|
||||
self.config = Arc::from(config);
|
||||
let _ = self.config.processes.iter()
|
||||
.for_each(|prc| {
|
||||
let (rx, tx) = mpsc::channel::<Events>(10);
|
||||
let temp = ProcessesController::new(&prc.name, tx).with_exe(&prc.path);
|
||||
|
|
@ -127,6 +129,9 @@ pub mod v2 {
|
|||
async fn process(&mut self) {
|
||||
info!("Initializing monitoring ...");
|
||||
loop {
|
||||
//
|
||||
// todo: CHANNEL check and reaction
|
||||
//
|
||||
// dbg!(&self);
|
||||
let mut tasks: Vec<tokio::task::JoinHandle<ControllerResult>> = vec![];
|
||||
// let (mut prc, mut file, mut serv) = (self.prcs.pop_front().unwrap(), self.files.pop_front().unwrap(), self.services.pop_front().unwrap());
|
||||
|
|
@ -177,7 +182,7 @@ pub mod v2 {
|
|||
pub async fn init_monitoring(
|
||||
config: Processes
|
||||
) -> anyhow::Result<()> {
|
||||
let mut supervisor = Supervisor::new().with_config(&config).await;
|
||||
let mut supervisor = Supervisor::new().with_config(config).await;
|
||||
info!("Monitoring: {} ", &supervisor.get_stats());
|
||||
supervisor.process().await;
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in New Issue