1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use crate::client::RainyClient;
use crate::error::Result;
use crate::models::{HealthStatus, ServiceStatus};
use serde::Deserialize;
impl RainyClient {
/// Performs a basic health check on the Rainy API.
///
/// This method is useful for quickly verifying that the API is up and running.
///
/// # Returns
///
/// A `Result` containing a `HealthStatus` struct with basic health information.
///
/// # Example
///
/// ```rust,no_run
/// # use rainy_sdk::RainyClient;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = RainyClient::with_api_key("user-api-key")?;
/// let health = client.health_check().await?;
/// println!("API Status: {}", health.status);
/// # Ok(())
/// # }
/// ```
pub async fn health_check(&self) -> Result<HealthStatus> {
#[derive(Deserialize)]
struct RootHealthResponse {
status: String,
timestamp: String,
}
let response = self
.http_client()
.get(self.root_url("/health"))
.send()
.await?;
let payload: RootHealthResponse = self.handle_response(response).await?;
Ok(HealthStatus {
status: payload.status,
timestamp: payload.timestamp,
uptime: 0.0,
services: ServiceStatus {
database: false,
redis: None,
providers: false,
},
})
}
/// Performs a detailed health check on the Rainy API and its underlying services.
///
/// This method provides more in-depth information, including the status of the database,
/// Redis, and connections to AI providers.
///
/// # Returns
///
/// A `Result` containing a `HealthStatus` struct with detailed service status.
///
/// # Example
///
/// ```rust,no_run
/// # use rainy_sdk::RainyClient;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = RainyClient::with_api_key("user-api-key")?;
/// let health = client.detailed_health_check().await?;
/// println!("Database status: {}", health.services.database);
/// println!("Providers status: {}", health.services.providers);
/// # Ok(())
/// # }
/// ```
pub async fn detailed_health_check(&self) -> Result<HealthStatus> {
#[derive(Deserialize)]
struct DependencyFlags {
database: bool,
redis: bool,
#[serde(rename = "openrouterConfigured")]
openrouter_configured: bool,
#[serde(rename = "polarConfigured")]
polar_configured: bool,
}
#[derive(Deserialize)]
struct DependenciesHealthResponse {
status: String,
timestamp: String,
dependencies: DependencyFlags,
}
let response = self
.http_client()
.get(self.root_url("/health/dependencies"))
.send()
.await?;
let payload: DependenciesHealthResponse = self.handle_response(response).await?;
Ok(HealthStatus {
status: payload.status,
timestamp: payload.timestamp,
uptime: 0.0,
services: ServiceStatus {
database: payload.dependencies.database,
redis: Some(payload.dependencies.redis),
providers: payload.dependencies.openrouter_configured
&& payload.dependencies.polar_configured,
},
})
}
}