ic_bn_lib/utils/health_manager.rs
1use std::sync::{Arc, RwLock};
2
3use ic_bn_lib_common::traits::Healthy;
4
5/// Aggregates objects that implement Healthy trait.
6/// It is healthy when all inner services are healthy.
7#[derive(Debug, Default)]
8pub struct HealthManager {
9 services: RwLock<Vec<Arc<dyn Healthy>>>,
10}
11
12impl HealthManager {
13 pub fn add(&self, svc: Arc<dyn Healthy>) {
14 self.services.write().unwrap().push(svc);
15 }
16}
17
18impl Healthy for HealthManager {
19 fn healthy(&self) -> bool {
20 self.services.read().unwrap().iter().all(|x| x.healthy())
21 }
22}