agentmux_srv_core/backend/container_status/
source.rs1use std::sync::Arc;
8
9use futures_util::stream::BoxStream;
10
11use super::{DockerEvent, Listed, Probe, Source};
12use crate::backend::container::ContainerRuntimeHandle;
13
14pub struct DockerSource {
15 handle: Arc<ContainerRuntimeHandle>,
16}
17
18impl DockerSource {
19 pub fn new(handle: Arc<ContainerRuntimeHandle>) -> Self {
20 Self { handle }
21 }
22}
23
24impl Source for DockerSource {
25 async fn ping(&self) -> Probe {
26 probe_of(&self.handle).await
27 }
28
29 async fn list(&self) -> Result<Vec<Listed>, String> {
30 let manager = self.handle.get().await.ok_or("no container runtime")?;
31 manager.agent_containers().await.map_err(|e| e.to_string())
32 }
33
34 async fn events(&self) -> Result<BoxStream<'static, Result<DockerEvent, String>>, String> {
35 let manager = self.handle.get().await.ok_or("no container runtime")?;
36 Ok(manager.agent_container_events())
37 }
38}
39
40pub async fn probe_of(handle: &ContainerRuntimeHandle) -> Probe {
42 let available = handle.is_available().await;
43 Probe {
44 available,
45 runtime: if available { handle.runtime_label().await } else { None },
46 detail: if available { None } else { handle.missing_message() },
47 }
48}