34 lines
1002 B
Rust
34 lines
1002 B
Rust
mod cmd;
|
|
|
|
use crate::command::service::CommandManagementService;
|
|
use crate::core::command_service_server::CommandServiceServer;
|
|
use crate::grpc::cmd::CoreCommandService;
|
|
use log::{error, info};
|
|
use std::sync::Arc;
|
|
use tokio::task::JoinHandle;
|
|
use tokio_util::sync::CancellationToken;
|
|
use tonic::transport::Server;
|
|
|
|
pub fn setup(
|
|
token: CancellationToken,
|
|
command_service: Arc<CommandManagementService>,
|
|
) -> anyhow::Result<JoinHandle<()>> {
|
|
let addr = "[::1]:50051".parse()?;
|
|
Ok(tokio::spawn(async move {
|
|
let cmd_service = CoreCommandService {
|
|
command_service,
|
|
cancellation_token: token.clone(),
|
|
};
|
|
|
|
info!("Starting gRPC Server");
|
|
let result = Server::builder()
|
|
.add_service(CommandServiceServer::new(cmd_service))
|
|
.serve_with_shutdown(addr, token.cancelled_owned())
|
|
.await;
|
|
|
|
if let Err(err) = result {
|
|
error!("gRPC Server Encountered An Error: {err}");
|
|
}
|
|
}))
|
|
}
|