saluki_core/health/
worker.rs1use async_trait::async_trait;
2use saluki_api::{DynamicRoute, EndpointType};
3use saluki_common::sync::shutdown::ShutdownHandle;
4use saluki_error::generic_error;
5
6use super::HealthRegistry;
7use crate::{
8 diagnostic::DiagnosticHandle,
9 runtime::{state::DataspaceRegistry, InitializationError, Supervisable, SupervisorFuture},
10};
11
12pub struct HealthRegistryWorker {
18 health_registry: HealthRegistry,
19}
20
21impl HealthRegistryWorker {
22 pub(super) fn new(health_registry: HealthRegistry) -> Self {
23 Self { health_registry }
24 }
25}
26
27#[async_trait]
28impl Supervisable for HealthRegistryWorker {
29 fn name(&self) -> &str {
30 "health-registry"
31 }
32
33 async fn initialize(&self, process_shutdown: ShutdownHandle) -> Result<SupervisorFuture, InitializationError> {
34 let runner = self.health_registry.clone().into_runner()?;
35
36 let health_routes = DynamicRoute::http(EndpointType::Unprivileged, self.health_registry.api_handler());
37
38 let health_registry = self.health_registry.clone();
39 let flare_handle = DiagnosticHandle::new("health.json", move || health_registry.snapshot_json().into_bytes());
40
41 Ok(Box::pin(async move {
42 let dataspace =
43 DataspaceRegistry::try_current().ok_or_else(|| generic_error!("Dataspace not available."))?;
44
45 dataspace.assert(health_routes, "health-registry-api");
47 dataspace.assert(flare_handle, "diag-health");
48
49 runner.run(process_shutdown).await;
58
59 Ok(())
60 }))
61 }
62}