- fix: when shutting down a docker container, the services would not deregister from consul correctly
This commit is contained in:
@@ -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("");
|
||||
|
||||
Reference in New Issue
Block a user