Make it work in nomad
This commit is contained in:
33
src/main.rs
33
src/main.rs
@ -7,6 +7,7 @@ mod udp;
|
||||
#[cfg(feature = "consul")]
|
||||
mod consul;
|
||||
|
||||
use config::ConfigProvider;
|
||||
use log::{debug, error, info, warn};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::error::Error;
|
||||
@ -39,15 +40,18 @@ async fn main() -> Result<()> {
|
||||
.chain(std::io::stdout())
|
||||
.apply()?;
|
||||
|
||||
let mut listeners: HashMap<String, ActiveListener> = HashMap::new();
|
||||
let listeners: HashMap<String, ActiveListener> = HashMap::new();
|
||||
let text_config_provider = config::FileConfigProvider::new();
|
||||
|
||||
let mut target_provider: Box<dyn config::ConfigProvider> = {
|
||||
let target_provider: Box<dyn config::ConfigProvider> = {
|
||||
#[cfg(feature = "consul")]
|
||||
{
|
||||
let cfg = text_config_provider.load_config()?;
|
||||
info!("Loaded yaml config");
|
||||
if cfg.consul.is_some() && cfg.consul.unwrap() {
|
||||
let consul_config_provider = consul::ConsulConfigProvider::new();
|
||||
info!("Using consul config provider");
|
||||
let consul_config_provider = consul::ConsulConfigProvider::new(Some(&cfg));
|
||||
info!("Loaded consul config provider");
|
||||
Box::new(consul_config_provider)
|
||||
} else {
|
||||
Box::new(text_config_provider)
|
||||
@ -55,9 +59,28 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "consul"))]
|
||||
Box::new(text_config_provider)
|
||||
{
|
||||
let cfg = Box::new(text_config_provider);
|
||||
info!("Loaded yaml config");
|
||||
cfg
|
||||
}
|
||||
};
|
||||
|
||||
match run_loop(target_provider, listeners).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
error!("Error in run loop: {}", e);
|
||||
info!("Exiting");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn run_loop(
|
||||
mut target_provider: Box<dyn ConfigProvider>,
|
||||
mut listeners: HashMap<String, ActiveListener>,
|
||||
) -> Result<()> {
|
||||
loop {
|
||||
let mappings = target_provider.get_targets().await?;
|
||||
let mut required_listeners: HashSet<String> = HashSet::new();
|
||||
@ -151,6 +174,6 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
target_provider.wait_for_change().await?;
|
||||
info!("Recevied SIGHUP, reloading config!");
|
||||
info!("Reloading config!");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user