(
store: Arc<Store>,
tx: watch::Sender<HealthState>,
interval: Duration,
timeout: Duration,
)
| 156 | } |
| 157 | |
| 158 | async fn monitor_loop( |
| 159 | store: Arc<Store>, |
| 160 | tx: watch::Sender<HealthState>, |
| 161 | interval: Duration, |
| 162 | timeout: Duration, |
| 163 | ) { |
| 164 | let mut ticker = tokio::time::interval(interval); |
| 165 | // `Skip` keeps the schedule when a tick is missed (e.g. because a ping |
| 166 | // approached the timeout). `Burst` (the default) would fire back-to-back |
| 167 | // catch-up pings, defeating the bounded-cadence guarantee. |
| 168 | ticker.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); |
| 169 | |
| 170 | loop { |
| 171 | ticker.tick().await; |
| 172 | let state = run_check(store.as_ref(), timeout).await; |
| 173 | record_metrics(&state); |
| 174 | // Send errors only happen when every receiver is dropped, at which |
| 175 | // point the monitor is shutting down — exit cleanly. |
| 176 | if tx.send(state).is_err() { |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | async fn run_check(store: &Store, timeout: Duration) -> HealthState { |
| 183 | let started = Instant::now(); |
no test coverage detected