Skip to main content

Mountain/Vine/Client/
CheckSideCarHealth.rs

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