Skip to main content

providers_kit/
runtime.rs

1//! Provider health observations.
2//!
3//! [`HealthStatus`] reports successful probe latency. A successful probe does not
4//! establish support or success for another model, file, batch, or session call.
5//! Shared shutdown belongs to [`crate::ProviderBackend::shutdown`].
6
7use std::future::Future;
8use std::time::{Duration, Instant};
9
10use serde::{Deserialize, Serialize};
11
12use crate::KitError;
13
14/// Successful provider health-probe result.
15///
16/// # Examples
17///
18/// ```
19/// let health = providers_kit::runtime::HealthStatus { latency: std::time::Duration::from_millis(12) };
20/// assert_eq!(health.latency.as_millis(), 12);
21/// ```
22///
23#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
24pub struct HealthStatus {
25    /// End-to-end probe latency.
26    pub latency: Duration,
27}
28
29impl HealthStatus {
30    pub(crate) async fn from_probe<T, F>(probe: F) -> Result<Self, KitError>
31    where
32        F: Future<Output = Result<T, KitError>>,
33    {
34        let start = Instant::now();
35        probe.await?;
36        Ok(Self {
37            latency: start.elapsed(),
38        })
39    }
40}