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