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:
@@ -109,7 +109,7 @@ impl ChatService for MyChatService {
|
||||
&clients_clone,
|
||||
);
|
||||
}
|
||||
// For other types, we simply broadcast as default.
|
||||
// For other types, we simply broadcast to all as default.
|
||||
_ => {
|
||||
let clients_lock = clients_clone.lock().unwrap();
|
||||
for (id, tx) in clients_lock.iter() {
|
||||
|
||||
@@ -3,6 +3,8 @@ mod chat_channels;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use tokio::time::{timeout, Duration};
|
||||
use tokio::sync::oneshot;
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns, get_service_endpoints_by_dns};
|
||||
use utils::{health_check, logging};
|
||||
use chat_service::MyChatService;
|
||||
@@ -10,6 +12,7 @@ use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tonic::transport::Server;
|
||||
use tracing::{info, error, warn};
|
||||
use crate::chat_service::chat::chat_service_server::ChatServiceServer;
|
||||
|
||||
#[tokio::main]
|
||||
@@ -31,21 +34,58 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
guild_channel: Arc::new(chat_channels::guild_chat::GuildChat),
|
||||
};
|
||||
|
||||
// Register service with Consul
|
||||
// Start gRPC server with graceful shutdown support
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter
|
||||
.set_serving::<ChatServiceServer<MyChatService>>()
|
||||
.await;
|
||||
let address = SocketAddr::new(addr.parse()?, port.parse()?);
|
||||
tokio::spawn(
|
||||
Server::builder()
|
||||
|
||||
// Create shutdown signal channel
|
||||
let (shutdown_tx, shutdown_rx) = oneshot::channel::<()>();
|
||||
|
||||
let server_task = tokio::spawn(async move {
|
||||
let server = Server::builder()
|
||||
.add_service(chat_service.into_service())
|
||||
.add_service(health_service)
|
||||
.serve(address),
|
||||
);
|
||||
.serve_with_shutdown(address, async {
|
||||
shutdown_rx.await.ok();
|
||||
info!("Chat service gRPC server shutdown signal received");
|
||||
});
|
||||
|
||||
println!("Chat Service listening on {}", address);
|
||||
|
||||
if let Err(e) = server.await {
|
||||
error!("Chat service gRPC server error: {}", e);
|
||||
} else {
|
||||
info!("Chat service gRPC server shut down gracefully");
|
||||
}
|
||||
});
|
||||
|
||||
info!("Chat Service listening on {}", address);
|
||||
|
||||
// Wait for shutdown signal
|
||||
info!("Chat 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!("Chat service gRPC server task failed: {}", e);
|
||||
} else {
|
||||
info!("Chat service shut down successfully");
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
error!("Chat service gRPC server shutdown timed out after 30 seconds");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user