- fix: when shutting down a docker container, the services would not deregister from consul correctly
This commit is contained in:
@@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
use tokio::{select, signal};
|
||||
use tokio::sync::Mutex;
|
||||
use tonic::transport::Server;
|
||||
use tracing::Level;
|
||||
use tracing::{info, Level};
|
||||
use utils::consul_registration;
|
||||
use utils::redis_cache::RedisCache;
|
||||
use utils::service_discovery::get_service_address;
|
||||
@@ -68,8 +68,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.add_service(SessionServiceServer::new(session_service))
|
||||
.serve(address));
|
||||
|
||||
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||
select! {
|
||||
_ = signal::ctrl_c() => {},
|
||||
_ = signal::ctrl_c() => {
|
||||
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||
},
|
||||
_ = sigterm_stream.recv() => {
|
||||
info!("Received SIGTERM, shutting down...");
|
||||
},
|
||||
}
|
||||
|
||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||
|
||||
Reference in New Issue
Block a user