api_shared/health.rs
1//! Health check utilities shared by both APIs.
2//!
3//! ## Purpose
4//! Provides a small helper for returning a standard health response.
5//!
6//! ## Intended use
7//! This module is used by both gRPC and REST implementations as a shared source of truth for the
8//! health response payload.
9
10use crate::pb::HealthRes;
11
12/// Simple health service that can be used by both gRPC and REST APIs
13///
14/// This service provides a standardised way to check the health status of the VPR system.
15/// It can be used both as a static utility and as an instantiated service.
16#[derive(Clone)]
17pub struct HealthService;
18
19impl HealthService {
20 /// Creates a new instance of HealthService.
21 ///
22 /// # Returns
23 /// A new `HealthService` instance.
24 pub fn new() -> Self {
25 Self
26 }
27
28 /// Static method to check health without creating an instance
29 ///
30 /// This is the preferred method for health checks as it doesn't require
31 /// instantiating the service.
32 ///
33 /// # Returns
34 /// A `HealthRes` indicating the service is healthy.
35 pub fn check_health() -> HealthRes {
36 HealthRes {
37 ok: true,
38 message: "VPR is alive".into(),
39 }
40 }
41
42 /// Instance method for compatibility
43 ///
44 /// This method is provided for backward compatibility but delegates
45 /// to the static `check_health()` method.
46 ///
47 /// # Returns
48 /// A `HealthRes` indicating the service is healthy.
49 pub fn check_health_instance(&self) -> HealthRes {
50 Self::check_health()
51 }
52}
53
54impl Default for HealthService {
55 fn default() -> Self {
56 Self::new()
57 }
58}