pub struct HealthChecker {
ping_timeout: Duration,
}Expand description
Connection health checker
This structure provides periodic health checking for connections, monitoring response times and overall connection health.
§Health Check Process
Connection
|
| 1. Send ping
v
Measure response time
|
| 2. Compare to timeout
v
Health decision (healthy/unhealthy)§Health Criteria
A connection is considered healthy if:
- Response time < ping_timeout (default 5 seconds)
§Example Usage
ⓘ
let checker = HealthChecker::new();
let mut handle = ConnectionHandle::new();
let is_healthy = checker.check_connection_health(&mut handle).await;Fields§
§ping_timeout: DurationMaximum allowed response time for a connection to be considered healthy
Implementations§
Source§impl HealthChecker
impl HealthChecker
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new health checker with default settings
Default ping timeout is 5 seconds.
Sourcepub fn with_timeout(ping_timeout: Duration) -> Self
pub fn with_timeout(ping_timeout: Duration) -> Self
Create a new health checker with custom timeout
§Parameters
ping_timeout: Maximum allowed response time
Sourcepub async fn check_connection_health(
&self,
handle: &mut ConnectionHandle,
) -> bool
pub async fn check_connection_health( &self, handle: &mut ConnectionHandle, ) -> bool
Check connection health by sending a ping
This method simulates a health check by measuring response time. In a production environment, this would send an actual ping message through the connection.
§Parameters
handle: Mutable reference to the connection handle to update based on health
§Returns
true: Connection is healthyfalse: Connection is unhealthy
§Example
ⓘ
let is_healthy = checker.check_connection_health(&mut handle).await;Sourcepub fn ping_timeout(&self) -> Duration
pub fn ping_timeout(&self) -> Duration
Get the ping timeout
Sourcepub fn set_ping_timeout(&mut self, timeout: Duration)
pub fn set_ping_timeout(&mut self, timeout: Duration)
Set a new ping timeout
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HealthChecker
impl RefUnwindSafe for HealthChecker
impl Send for HealthChecker
impl Sync for HealthChecker
impl Unpin for HealthChecker
impl UnwindSafe for HealthChecker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].