diff --git a/src/endpoint.rs b/src/endpoint.rs index 3bf6665..f35d009 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,8 +1,12 @@ +use eyre::Result; use async_trait::async_trait; +use tokio::sync::oneshot; +use std::sync::Arc; #[async_trait] pub trait Endpoint { fn name(&self) -> String; - + fn is_active(&self) -> bool; + async fn listen(self: Arc, success_status_send: oneshot::Sender>); } diff --git a/src/main.rs b/src/main.rs index 4388fb2..570070f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,5 +12,7 @@ use state::RircdState; async fn main() -> Result<()> { let s = RircdState::new()?; + s.run().await?; + Ok(()) } diff --git a/src/state.rs b/src/state.rs index f44ea7e..3a88e17 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,6 +1,8 @@ use eyre::Result; +use async_trait::async_trait; use std::time::Instant; use std::sync::Arc; +use tokio::sync::oneshot; use crate::endpoint::Endpoint; @@ -25,4 +27,24 @@ impl RircdState { postgres_log: None, }) } + + //TODO impl + pub fn from_config(config: String) -> Result { + Self::new() + } + + pub async fn run(mut self) -> Result<()> { + for endpoint in self.endpoints { + let endpoint_name = endpoint.name(); + let (success_status_send,success_status_recv) = oneshot::channel::>(); + tokio::spawn(endpoint.listen(success_status_send)); + //TODO color err msg + println!("starting {} | {}", endpoint_name, + match success_status_recv.await { + Ok(_) => format!("SUCCEEDED |"), + Err(e) => format!("FAILED| <{}>", e), + }); + } + Ok(()) + } }