- fix: when shutting down a docker container, the services would not deregister from consul correctly

This commit is contained in:
2024-12-20 17:42:50 -05:00
parent 18afa71d74
commit e3fb186a44
7 changed files with 54 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::env;
use std::str::FromStr;
use tokio::{select, signal};
use tracing::Level;
use tracing::{info, Level};
use utils::consul_registration;
use utils::service_discovery::get_service_address;
@@ -50,8 +50,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db_address = db_nodes.get(0).unwrap();
let db_url = format!("http://{}:{}", db_address.ServiceAddress, db_address.ServicePort);
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("");