integration-module/crates/api-grub/src/main.rs

44 lines
1.1 KiB
Rust

mod config;
mod net;
mod logger;
use anyhow::Result;
use integr_structs::api::ApiConfigV2;
use logger::setup_logger;
use log::{info, warn};
use config::{pull_local_config, init_config_grub_mechanism};
use net::init_api_grub_mechanism;
use tokio::sync::mpsc;
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()>{
// 3 coroutines
// 1) unix-socket coroutine (for config updating)
// 2) api coroutine
// 3) ?
setup_logger().await?;
let config = get_config().await;
// config update channel
let (tx, mut rx) = mpsc::channel::<ApiConfigV2>(1);
// futures
// todo : rewrite with spawn
let config_fut = init_config_grub_mechanism(&tx);
let grub_fut = init_api_grub_mechanism(config, &mut rx);
let _ = tokio::join!(config_fut, grub_fut);
Ok(())
}
async fn get_config() -> ApiConfigV2 {
return match pull_local_config().await {
Ok(conf) => {
info!("Local config was loaded");
conf
},
Err(er) => {
warn!("Cannot get local config due to {}", er);
ApiConfigV2::default()
}
}
}