make a few optimisations in executor
This commit is contained in:
parent
14b762520f
commit
92e01299bc
5 changed files with 45 additions and 32 deletions
|
@ -1,41 +1,17 @@
|
|||
|
||||
|
||||
pub mod sent_signal;
|
||||
|
||||
use crate::status_obj;
|
||||
pub mod execute_service;
|
||||
|
||||
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;
|
||||
|
||||
for sv in services {
|
||||
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.clone();
|
||||
} else {
|
||||
// case relative path for the service.
|
||||
//
|
||||
path = svdir_var.clone() + "/" + &sv;
|
||||
exit_code += execute_service::execute_service(svdir_var.clone(), svwait_var, verbose, command, sv);
|
||||
if exit_code > 99 {
|
||||
exit_code = 99;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
|
|
22
01_phase_rust_src/sv-rustit/src/executor/execute_service.rs
Normal file
22
01_phase_rust_src/sv-rustit/src/executor/execute_service.rs
Normal 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;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
|
@ -31,5 +31,3 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue