diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2024-10-13 20:44:03 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2024-10-13 20:44:03 -0500 |
commit | d3768b1d9712436da6df4e1eef54737890035f62 (patch) | |
tree | 11f9dfb2595b0d19f7811d13ceff6ef076b7d5ec /src | |
parent | aac6390f82d1f8626c466b531870dc5bde080f87 (diff) |
feat: improve ui and add test service
Diffstat (limited to 'src')
-rw-r--r-- | src/service.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<Output = ()>; } +impl IntoService for () { + async fn into_service(self, tx: tokio::sync::watch::Sender<Status>) { + 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<Status>) { 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, |