Consul Actor basic logic works

This commit is contained in:
Quentin 2020-05-22 12:29:55 +02:00
parent efbbc17f82
commit 4cebe77b6f
2 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ fn retry_to_time(retries: u32, max_time: Duration) -> Duration {
} }
impl ConsulActor { impl ConsulActor {
fn new(url: &str, node: &str) -> Self { pub fn new(url: &str, node: &str) -> Self {
let (tx, rx) = watch::channel(messages::OpenPorts{ports: Vec::new() }); let (tx, rx) = watch::channel(messages::OpenPorts{ports: Vec::new() });
return Self { return Self {
consul: Consul::new(url), consul: Consul::new(url),
@ -34,7 +34,7 @@ impl ConsulActor {
}; };
} }
async fn listen(&mut self) -> Result<()> { pub async fn listen(&mut self) -> Result<()> {
loop { loop {
let catalog = match self.consul.watch_node(&self.node).await { let catalog = match self.consul.watch_node(&self.node).await {
Ok(c) => c, Ok(c) => c,
@ -46,6 +46,8 @@ impl ConsulActor {
continue; continue;
} }
}; };
info!("{:#?}", catalog);
} }
} }
} }

View File

@ -6,21 +6,19 @@ mod consul_actor;
//use std::collections::HashMap; //use std::collections::HashMap;
//use igd::PortMappingProtocol; //use igd::PortMappingProtocol;
use log::*; use log::*;
use consul::*; use consul_actor::*;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
info!("Starting Diplonat"); info!("Starting Diplonat");
/* /*
let diplo = Diplonat::new().await.expect("Setup failed"); let diplo = Diplonat::new().await.expect("Setup failed");
diplo.listen().await.expect("A runtime error occured"); diplo.listen().await.expect("A runtime error occured");
*/ */
let mut c = Consul::new("http://127.0.0.1:8500");
let cn = c.watch_node("lheureduthe").await.expect("Failed to fetch API"); let mut ca = ConsulActor::new("http://127.0.0.1:8500", "lheureduthe");
println!("{:#?}", cn); ca.listen().await.expect("Oooooops");
let cn2 = c.watch_node("lheureduthe").await.expect("Failed to fetch API");
println!("{:#?}", cn2);
/* /*
let gateway = match search_gateway(Default::default()).await { let gateway = match search_gateway(Default::default()).await {