You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

71 lines
2.0 KiB

// TODO:
// поддержка питона
// резолв адреса управляющего сервера через DoT
// кроссплатформенность (реализовать интерфейс для винды и никсов)
// проверка обнов
// самоуничтожение
#[macro_use]
extern crate log;
extern crate env_logger;
use std::env;
use u_lib::{
api::ClientHandler,
models::{gather},
build_jobs_with_result,
UID,
JobResult,
JobCache
};
use tokio::{time::{Duration, sleep}};
#[macro_export]
macro_rules! retry_until_ok {
( $body:expr ) => {
loop {
match $body {
Ok(r) => break r,
Err(e) => error!("{:?}", e)
};
sleep(Duration::from_secs(5)).await;
}
}
}
#[tokio::main]
async fn main() {
//daemonize();
env_logger::init();
let arg_ip = env::args().nth(1);
let instance = ClientHandler::new(arg_ip);
let cli_info = gather().await;
info!("Connecting to the server");
retry_until_ok!(instance.init(&cli_info).await);
info!("Instanciated! Running main loop");
loop {
let job_requests: Vec<JobResult> =
retry_until_ok!(instance.get_agent_jobs(Some(&*UID)).await);
if job_requests.len() > 0 {
for jr in job_requests.iter() {
if !JobCache::contains(&jr.job_id) {
info!("Fetching job: {}", &jr.job_id);
let fetched_job =
retry_until_ok!(instance.get_jobs(Some(&jr.job_id)).await).pop().unwrap();
JobCache::insert(fetched_job);
}
};
let result = build_jobs_with_result(job_requests)
.run_until_complete()
.await
.into_iter()
.map(|r| r.unwrap())
.collect();
retry_until_ok!(instance.report(
&result
).await)
}
sleep(Duration::from_secs(5)).await;
}
}