Tons of fixes
Added movement updates Updated how entities are checked Events sending between packet service all the way to the logic service
This commit is contained in:
@@ -6,8 +6,10 @@ use auth_service::session::session_service_client::SessionServiceClient;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::time::{timeout, Duration};
|
||||
use tonic::transport::Server;
|
||||
use tracing::info;
|
||||
use tracing::{info, error, warn};
|
||||
use utils::logging;
|
||||
use utils::service_discovery::get_kube_service_endpoints_by_dns;
|
||||
|
||||
@@ -40,19 +42,55 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
session_client,
|
||||
};
|
||||
|
||||
// Start gRPC server with graceful shutdown support
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter.set_serving::<AuthServiceServer<MyAuthService>>().await;
|
||||
|
||||
info!("Authentication Service running on {}", addr);
|
||||
// Create shutdown signal channel
|
||||
let (shutdown_tx, shutdown_rx) = oneshot::channel::<()>();
|
||||
|
||||
// Start the gRPC server
|
||||
tokio::spawn(
|
||||
Server::builder()
|
||||
let server_task = tokio::spawn(async move {
|
||||
let server = Server::builder()
|
||||
.add_service(health_service)
|
||||
.add_service(AuthServiceServer::new(auth_service))
|
||||
.serve(address),
|
||||
);
|
||||
.serve_with_shutdown(address, async {
|
||||
shutdown_rx.await.ok();
|
||||
info!("Auth service gRPC server shutdown signal received");
|
||||
});
|
||||
|
||||
if let Err(e) = server.await {
|
||||
error!("Auth service gRPC server error: {}", e);
|
||||
} else {
|
||||
info!("Auth service gRPC server shut down gracefully");
|
||||
}
|
||||
});
|
||||
|
||||
info!("Authentication Service running on {}", addr);
|
||||
|
||||
// Wait for shutdown signal
|
||||
info!("Auth service is running. Waiting for shutdown signal...");
|
||||
utils::signal_handler::wait_for_signal().await;
|
||||
|
||||
info!("Shutdown signal received. Beginning graceful shutdown...");
|
||||
|
||||
// Signal the gRPC server to stop accepting new connections
|
||||
if let Err(_) = shutdown_tx.send(()) {
|
||||
warn!("Failed to send shutdown signal to gRPC server (receiver may have been dropped)");
|
||||
}
|
||||
|
||||
// Wait for the gRPC server to finish with a timeout
|
||||
match timeout(Duration::from_secs(30), server_task).await {
|
||||
Ok(result) => {
|
||||
if let Err(e) = result {
|
||||
error!("Auth service gRPC server task failed: {}", e);
|
||||
} else {
|
||||
info!("Auth service shut down successfully");
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
error!("Auth service gRPC server shutdown timed out after 30 seconds");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user