From 86c255dfeabc60b0ef46ff78bc487c61c9548c79 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 11 Jan 2023 22:44:21 +0100 Subject: Less spam on stdout --- src/dns_config.rs | 2 +- src/main.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/dns_config.rs b/src/dns_config.rs index 1356fc7..0697270 100644 --- a/src/dns_config.rs +++ b/src/dns_config.rs @@ -19,7 +19,7 @@ const CNAME_TARGET_METADATA_TAG: &str = "cname_target"; // ---- Extract DNS config from Consul catalog ---- -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq, Default)] pub struct DnsConfig { pub entries: HashMap, } diff --git a/src/main.rs b/src/main.rs index 77c8b16..24193f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,6 +129,8 @@ async fn dump_config_on_change( mut rx_dns_config: watch::Receiver>, mut must_exit: watch::Receiver, ) { + let mut prev_dns_config = Arc::new(dns_config::DnsConfig::default()); + while !*must_exit.borrow() { select!( c = rx_dns_config.changed() => { @@ -138,11 +140,16 @@ async fn dump_config_on_change( } _ = must_exit.changed() => continue, ); - println!("---- DNS CONFIGURATION ----"); - for (k, v) in rx_dns_config.borrow().entries.iter() { - println!(" {} {}", k, v); + + let new_dns_config = rx_dns_config.borrow_and_update().clone(); + if new_dns_config != prev_dns_config { + println!("---- DNS CONFIGURATION ----"); + for (k, v) in rx_dns_config.borrow().entries.iter() { + println!(" {} {}", k, v); + } + println!(); } - println!(); + prev_dns_config = new_dns_config; } } -- cgit v1.2.3