make a few optimisations in executor

This commit is contained in:
primardj 2024-04-16 00:04:29 +01:00
parent 14b762520f
commit 92e01299bc
5 changed files with 45 additions and 32 deletions

View file

@ -1,41 +1,17 @@
pub mod sent_signal; pub mod execute_service;
use crate::status_obj;
pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>) -> i32{ pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>) -> i32{
// split a service vector into different sv.
let mut exit_code: i32 = 0; let mut exit_code: i32 = 0;
for sv in services { for sv in services {
let ch1 = sv.chars().next().unwrap(); exit_code += execute_service::execute_service(svdir_var.clone(), svwait_var, verbose, command, sv);
let ch2_row = &sv.chars().collect::<Vec<_>>()[..2]; if exit_code > 99 {
let ch2: String = ch2_row.into_iter().collect(); exit_code = 99;
let path;
if ch1 == '/' || ch2 == "~/"{
// case absolute path for the service
//
path = sv.clone();
} else {
// case relative path for the service.
//
path = svdir_var.clone() + "/" + &sv;
} }
let status_option = status_obj::StatusObj::new(path, sv);
match status_option {
Some(status) => {
exit_code += sent_signal::sent_signal(svwait_var, verbose, command, status);
},
None => {
if exit_code < 99 {
exit_code += 1;
}
},
};
} }
return exit_code return exit_code
} }

View file

@ -0,0 +1,22 @@
mod sent_signal;
mod make_path;
use crate::status_obj;
pub fn execute_service(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, sv: String) -> i32 {
// make a sv object from a string, svdir_var, and sent it the command signal.
let path = make_path::make_path(svdir_var, sv.clone());
let status_option = status_obj::StatusObj::new(path, sv);
match status_option {
Some(status) => {
return sent_signal::sent_signal(svwait_var, verbose, command, status);
},
None => {
return 1;
},
};
}

View file

@ -0,0 +1,17 @@
pub fn make_path(svdir_var: String, sv: String) -> String {
let ch1 = sv.chars().next().unwrap();
let ch2_row = &sv.chars().collect::<Vec<_>>()[..2];
let ch2: String = ch2_row.into_iter().collect();
let path;
if ch1 == '/' || ch2 == "~/"{
// case absolute path for the service
path = sv;
} else {
// case relative path for the service.
path = svdir_var + "/" + &sv;
}
return path
}

View file

@ -31,5 +31,3 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
}; };
} }