Mountain/Vine/Client/CheckSideCarHealth.rs
1#![allow(non_snake_case)]
2
3//! Health check: connection exists in the pool, last activity within
4//! `HEALTH_CHECK_INTERVAL_MS`, and failure count below the retry
5//! threshold.
6
7use std::time::Duration;
8
9use crate::Vine::{
10 Client::Shared::{CONNECTION_METADATA, HEALTH_CHECK_INTERVAL_MS, MAX_RETRY_ATTEMPTS},
11 Error::VineError,
12};
13
14pub fn Fn(SideCarIdentifier:&str) -> Result<bool, VineError> {
15 let Metadata = CONNECTION_METADATA.lock();
16
17 if let Some(Connection) = Metadata.get(SideCarIdentifier) {
18 let IsStale = Connection.LastActivity.elapsed() > Duration::from_millis(HEALTH_CHECK_INTERVAL_MS);
19 let HasManyFailures = Connection.FailureCount > MAX_RETRY_ATTEMPTS;
20 Ok(Connection.IsHealthy && !IsStale && !HasManyFailures)
21 } else {
22 Err(VineError::ClientNotConnected(SideCarIdentifier.to_string()))
23 }
24}