use wacht::api::health::*;
use std::time::Duration;
use tokio::time::timeout;
// Ping with timeout
async fn check_api_connectivity() -> bool {
match timeout(Duration::from_secs(5), ping()).await {
Ok(Ok(true)) => {
println!("✅ API is online");
true
}
Ok(Ok(false)) => {
println!("❌ API returned false");
false
}
Ok(Err(e)) => {
println!("❌ Ping error: {}", e);
false
}
Err(_) => {
println!("❌ Ping timeout after 5 seconds");
false
}
}
}
// Retry logic
async fn ping_with_retry(max_attempts: u32) -> bool {
for attempt in 1..=max_attempts {
println!("Ping attempt {}/{}", attempt, max_attempts);
if ping().await.unwrap_or(false) {
return true;
}
if attempt < max_attempts {
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
false
}