chore: add run_check_app

This commit is contained in:
Jesús Pérez Lorenzo 2021-10-09 01:00:45 +01:00
parent 97a2bfa891
commit 9f77102f3a

View File

@ -24,7 +24,7 @@ use crate::defs::{DataDBs,CollsData,load_cloud_env};
use clds::clouds::defs::{ use clds::clouds::defs::{
Cloud, Cloud,
}; };
use clds::clouds::on_clouds::{make_cloud_cache,run_clouds_check}; use clds::clouds::on_clouds::{make_cloud_cache,run_clouds_check,run_apps_check};
use reqenv::ReqEnv; use reqenv::ReqEnv;
// static WEBSERVER: AtomicUsize = AtomicUsize::new(0); // static WEBSERVER: AtomicUsize = AtomicUsize::new(0);
@ -60,7 +60,7 @@ async fn up_web_server(webpos: usize) -> Result<()> {
format!("authors: {}",PKG_AUTHORS), format!("authors: {}",PKG_AUTHORS),
format!("{}",PKG_DESCRIPTION), format!("{}",PKG_DESCRIPTION),
); );
zterton::init_app(&mut app_env,verbose).await.unwrap_or_else(|e| webenv::init_app(&mut app_env,verbose).await.unwrap_or_else(|e|
panic!("Error loadding app environment {}",e) panic!("Error loadding app environment {}",e)
); );
let config = app_env.get_curr_websrvr_config(); let config = app_env.get_curr_websrvr_config();
@ -78,7 +78,7 @@ async fn up_web_server(webpos: usize) -> Result<()> {
if verbose > 0 { if verbose > 0 {
println!("Loading webserver: {} ({})",&config.name,&app_env.curr_web); println!("Loading webserver: {} ({})",&config.name,&app_env.curr_web);
} }
let (app, socket) = zterton::start_web(&mut app_env).await; let (app, socket) = webenv::start_web(&mut app_env).await;
if verbose > 0 { if verbose > 0 {
println!("Load app store ..."); println!("Load app store ...");
} }
@ -250,14 +250,35 @@ pub async fn run_check_clouds() -> Result<()> {
let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await { let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await {
Ok((c,e)) => (c,e), Ok((c,e)) => (c,e),
Err(e) => { Err(e) => {
println!("Check Cloud service: done {} __________ ",&now); println!("Check Cloud services: done {} __________ ",&now);
return Err(e); return Err(e);
}, },
}; };
let reqenv = set_reqenv(&app_env,verbose).await; let reqenv = set_reqenv(&app_env,verbose).await;
let res = run_clouds_check(&reqenv,&cloud).await; let res = run_clouds_check(&reqenv,&cloud).await;
if verbose > 0 { if verbose > 0 {
println!("Check Cloud service: done {} __________ ",&now); println!("Check Cloud services: done {} __________ ",&now);
}
res
}
pub async fn run_check_apps() -> Result<()> {
let (arg_cfg_path,arg_env_path) = get_args();
let now = chrono::Utc::now().timestamp();
let verbose = envmnt::get_isize("DEBUG", 0);
if verbose > 0 {
println!("Check Apps services: run {} __________ {} {} ",&now,&arg_cfg_path,&arg_env_path);
}
let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await {
Ok((c,e)) => (c,e),
Err(e) => {
println!("Check Apps services: done {} __________ ",&now);
return Err(e);
},
};
let reqenv = set_reqenv(&app_env,verbose).await;
let res = run_apps_check(&reqenv,&cloud).await;
if verbose > 0 {
println!("Check Apps services: done {} __________ ",&now);
} }
res res
} }
@ -295,12 +316,14 @@ pub async fn main() -> BxDynResult<()> { //std::io::Result<()> {
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
if args.len() > 1 { if args.len() > 1 {
match args[1].as_str() { match args[1].as_str() {
"-h" | "--help" => "-h" | "--help" => {
println!("{} USAGE: -c config-toml -e env.file",PKG_NAME), println!("{} USAGE: -c config-toml -e env.file",PKG_NAME);
return Ok(());
},
"-v" | "--version" => { "-v" | "--version" => {
println!("{} version: {}",PKG_NAME,PKG_VERSION); println!("{} version: {}",PKG_NAME,PKG_VERSION);
return Ok(()); return Ok(());
}, },
_ => println!("{}",PKG_NAME), _ => println!("{}",PKG_NAME),
} }
} }
@ -338,6 +361,7 @@ pub async fn main() -> BxDynResult<()> { //std::io::Result<()> {
"monitor" => tokio::spawn(async {run_clouds_monitor().await}), "monitor" => tokio::spawn(async {run_clouds_monitor().await}),
"check" => tokio::spawn(async {run_check_clouds().await}), "check" => tokio::spawn(async {run_check_clouds().await}),
"cache" => tokio::spawn(async {run_cache_clouds().await}), "cache" => tokio::spawn(async {run_cache_clouds().await}),
"apps" => tokio::spawn(async {run_check_apps().await}),
_ => { _ => {
eprintln!("Error task {} not defined",&it.name); eprintln!("Error task {} not defined",&it.name);
continue; continue;
@ -375,6 +399,13 @@ pub async fn main() -> BxDynResult<()> { //std::io::Result<()> {
} }
tokio::spawn(async {run_check_clouds().await}); tokio::spawn(async {run_check_clouds().await});
})?), })?),
"apps" =>
sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| {
if debug > 0 {
println!("Schedule {} {}: {}",&it.name,&it.schedule,uuid);
}
tokio::spawn(async {run_check_apps().await});
})?),
"cache" => "cache" =>
sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| { sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| {
if debug > 0 { if debug > 0 {