feat(xy): daemon Registry with config-hash entries
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
use crate::paths::Paths;
|
use crate::paths::Paths;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
|
|
||||||
|
pub mod registry;
|
||||||
|
|
||||||
pub async fn run(_paths: Paths) -> Result<()> { bail!("not implemented") }
|
pub async fn run(_paths: Paths) -> Result<()> { bail!("not implemented") }
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
use xy_supervisor::SupervisorHandle;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Entry {
|
||||||
|
pub handle: SupervisorHandle,
|
||||||
|
pub config_hash: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
pub struct Registry {
|
||||||
|
inner: Arc<RwLock<HashMap<String, Entry>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Registry {
|
||||||
|
pub fn new() -> Self { Self::default() }
|
||||||
|
pub async fn insert(&self, name: String, entry: Entry) {
|
||||||
|
self.inner.write().await.insert(name, entry);
|
||||||
|
}
|
||||||
|
pub async fn remove(&self, name: &str) -> Option<Entry> {
|
||||||
|
self.inner.write().await.remove(name)
|
||||||
|
}
|
||||||
|
pub async fn get(&self, name: &str) -> Option<Entry> {
|
||||||
|
self.inner.read().await.get(name).cloned()
|
||||||
|
}
|
||||||
|
pub async fn names(&self) -> Vec<String> {
|
||||||
|
let g = self.inner.read().await;
|
||||||
|
let mut v: Vec<String> = g.keys().cloned().collect();
|
||||||
|
v.sort(); v
|
||||||
|
}
|
||||||
|
pub async fn snapshot(&self) -> Vec<(String, Entry)> {
|
||||||
|
let g = self.inner.read().await;
|
||||||
|
let mut v: Vec<_> = g.iter().map(|(k, v)| (k.clone(), v.clone())).collect();
|
||||||
|
v.sort_by(|a, b| a.0.cmp(&b.0));
|
||||||
|
v
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user