summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-10-12 18:23:46 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-10-12 18:23:46 -0500
commit8b9eb6eb88d871309348dff1527d69b4b32a98ec (patch)
tree4a8d25f3b0db4a6ff7c258f3ea7a508e6b68de82 /src/state.rs
parent0ea877c5d0de10b45768da80c658785835d625e6 (diff)
refactor: simplify service trait, again
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/state.rs b/src/state.rs
index c442d9d..857b8af 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -5,7 +5,7 @@ use tokio::sync::watch::Receiver;
use tokio_stream::wrappers::WatchStream;
use crate::{
- service::{IntoService, ServiceConfig, ServiceKind},
+ service::{IntoService, ServiceConfig},
Status,
};
@@ -22,30 +22,20 @@ impl AppState {
.into_iter()
.map(|ServiceConfig { name, kind }| {
indexes.push(name.clone());
+ tracing::debug!(name, "Added service");
let (tx, rx) = tokio::sync::watch::channel(Status::default());
- tokio::spawn(Self::spawn_service(kind, tx.clone()));
+ tokio::spawn(kind.into_service(tx.clone()));
(name, rx)
})
.collect();
+ tracing::debug!(?indexes, "Finished spawning services");
+
AppState { rx_map, indexes }
}
- #[tracing::instrument(skip(tx))]
- async fn spawn_service(kind: ServiceKind, tx: tokio::sync::watch::Sender<Status>) {
- let mut stream = kind.into_service();
- while let Some(res) = stream.next().await {
- let status = res.into();
- tx.send_if_modified(|s| {
- if *s != status {
- tracing::debug!(?status, "Updated service status");
- *s = status;
- true
- } else {
- false
- }
- });
- }
+ pub fn names(&self) -> Vec<String> {
+ self.indexes.clone()
}
pub fn status(&self, k: &str) -> Option<Status> {