From d3768b1d9712436da6df4e1eef54737890035f62 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sun, 13 Oct 2024 20:44:03 -0500 Subject: feat: improve ui and add test service --- src/service.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/service.rs') diff --git a/src/service.rs b/src/service.rs index b67ba51..74ecb1d 100644 --- a/src/service.rs +++ b/src/service.rs @@ -13,6 +13,21 @@ pub trait IntoService { ) -> impl std::future::Future; } +impl IntoService for () { + async fn into_service(self, tx: tokio::sync::watch::Sender) { + let mut interval = tokio::time::interval(std::time::Duration::from_secs(3)); + let mut status = Status::Ok; + + loop { + interval.tick().await; + status = match tx.send_replace(status) { + Status::Ok => Status::Error(Some("Test status is in the error state".into())), + Status::Error(_) => Status::Ok, + }; + } + } +} + pub fn default_interval() -> std::time::Duration { std::time::Duration::from_secs(5) } @@ -31,11 +46,13 @@ pub enum ServiceKind { Http(http::Http), Tcp(tcp::Tcp), Exec(command::Command), + Test(()), } impl IntoService for ServiceKind { async fn into_service(self, tx: tokio::sync::watch::Sender) { match self { + ServiceKind::Test(()) => ().into_service(tx).await, ServiceKind::Http(h) => h.into_service(tx).await, ServiceKind::Tcp(t) => t.into_service(tx).await, ServiceKind::Exec(c) => c.into_service(tx).await, -- cgit v1.2.3-70-g09d2