yotei/yotei-nodes/src/compute.rs
2024-09-11 19:10:12 +02:00

73 lines
2.1 KiB
Rust

use std::net::SocketAddr;
mod grpc;
mod config;
use crate::config::CONFIG;
use log::{debug, info};
use sched::LoginRequest;
pub mod sched {
tonic::include_proto!("sched");
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("RUST_LOG", CONFIG.log.level.clone());
pretty_env_logger::init();
use colorful::Color;
use colorful::Colorful;
use colorful::HSL;
println!(" {}", "+--------------+".color(Color::LightBlue));
println!(" {}", "| 予定 |".color(Color::LightPink1));
println!(
" {}",
"+--------------+".color(colorful::RGB::new(252, 252, 252))
);
println!(" {}", "YOITEI SCHEDULER".color(Color::LightPink1));
println!(" {}", " COMPUTE NODE\n".color(Color::LightBlue));
let server_addr = "http://[::1]:50051";
let addr: SocketAddr = "[::1]:50053".parse()?;
let data = sched::data_client::DataClient::connect(server_addr).await?;
let mut auth = sched::auth_client::AuthClient::connect(server_addr).await?;
// Start server here
let alive_check_server = alive_check_serve(addr);
debug!(
"{:#?}",
auth.login(tonic::Request::new(LoginRequest {
node_id: "compute-1".to_string(),
}))
.await?
);
// Await server at end
alive_check_server.await?;
Ok(())
}
async fn alive_check_serve(addr: SocketAddr) -> Result<(), Box<dyn std::error::Error>> {
use grpc::AliveCheckService;
use sched::alive_check_server::AliveCheckServer;
use tokio::sync::mpsc;
use tokio::task;
use tonic::transport::Server;
let (tx, mut rx) = mpsc::channel::<Server>(100);
task::spawn(async move {
info!(
"Starting Alive Check gRPC server on: http://{}",
addr.to_string()
);
let alive_check_service = AliveCheckService::default();
Server::builder()
.add_service(AliveCheckServer::new(alive_check_service))
.serve(addr)
.await
.unwrap();
});
while let Some(msg) = rx.recv().await {
println!("REC: {:?}", msg);
}
Ok(())
}