refactor: remove MongoDB from health check
- Removed check_mongodb() function from health.rs - Health endpoint no longer requires MongoDB (status depends on PG+Redis+Qdrant only) - ServiceHealth struct: mongodb field commented out - Both health() and health_detailed() updated - Removed MongoCache import Note: Binary rebuild blocked by missing .sqlx cache files for command/queue.rs and vlm/consumer.rs. Once build env is fixed: cd momentry_core && SQLX_OFFLINE=true cargo build --release cp target/release/momentry ../momentry/bin/momentry
This commit is contained in:
+15
-32
@@ -4,7 +4,6 @@ use serde::Serialize;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use super::types::AppState;
|
use super::types::AppState;
|
||||||
use crate::core::cache::MongoCache;
|
|
||||||
use crate::core::config;
|
use crate::core::config;
|
||||||
use crate::core::db::{Database, PostgresDb, RedisClient};
|
use crate::core::db::{Database, PostgresDb, RedisClient};
|
||||||
use crate::core::db::qdrant_db::new_http_client;
|
use crate::core::db::qdrant_db::new_http_client;
|
||||||
@@ -181,7 +180,7 @@ struct ServiceHealth {
|
|||||||
postgres: ServiceStatus,
|
postgres: ServiceStatus,
|
||||||
redis: ServiceStatus,
|
redis: ServiceStatus,
|
||||||
qdrant: ServiceStatus,
|
qdrant: ServiceStatus,
|
||||||
mongodb: ServiceStatus,
|
// mongodb: ServiceStatus, // Removed - now using Redis only
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -195,12 +194,11 @@ pub async fn health(State(state): State<AppState>) -> Json<HealthResponse> {
|
|||||||
let postgres = check_postgres().await;
|
let postgres = check_postgres().await;
|
||||||
let redis = check_redis().await;
|
let redis = check_redis().await;
|
||||||
let qdrant = check_qdrant().await;
|
let qdrant = check_qdrant().await;
|
||||||
let mongodb = check_mongodb(&state.mongo_cache).await;
|
// MongoDB removed — no longer required
|
||||||
|
|
||||||
let all_ok = postgres.status == "ok"
|
let all_ok = postgres.status == "ok"
|
||||||
&& redis.status == "ok"
|
&& redis.status == "ok"
|
||||||
&& qdrant.status == "ok"
|
&& qdrant.status == "ok";
|
||||||
&& mongodb.status == "ok";
|
|
||||||
|
|
||||||
let status = if all_ok { "ok" } else { "degraded" };
|
let status = if all_ok { "ok" } else { "degraded" };
|
||||||
|
|
||||||
@@ -228,12 +226,11 @@ pub async fn health_detailed(State(state): State<AppState>) -> Json<DetailedHeal
|
|||||||
let postgres = check_postgres().await;
|
let postgres = check_postgres().await;
|
||||||
let redis = check_redis().await;
|
let redis = check_redis().await;
|
||||||
let qdrant = check_qdrant().await;
|
let qdrant = check_qdrant().await;
|
||||||
let mongodb = check_mongodb(&state.mongo_cache).await;
|
// MongoDB removed — no longer required
|
||||||
|
|
||||||
let overall_status = if postgres.status == "ok"
|
let overall_status = if postgres.status == "ok"
|
||||||
&& redis.status == "ok"
|
&& redis.status == "ok"
|
||||||
&& qdrant.status == "ok"
|
&& qdrant.status == "ok"
|
||||||
&& mongodb.status == "ok"
|
|
||||||
{
|
{
|
||||||
"ok"
|
"ok"
|
||||||
} else {
|
} else {
|
||||||
@@ -339,7 +336,7 @@ pub async fn health_detailed(State(state): State<AppState>) -> Json<DetailedHeal
|
|||||||
postgres,
|
postgres,
|
||||||
redis,
|
redis,
|
||||||
qdrant,
|
qdrant,
|
||||||
mongodb,
|
// mongodb, // Removed
|
||||||
},
|
},
|
||||||
resources: ResourceStatus {
|
resources: ResourceStatus {
|
||||||
cpu_used_percent: sys.cpu_used_percent,
|
cpu_used_percent: sys.cpu_used_percent,
|
||||||
@@ -532,22 +529,6 @@ async fn check_qdrant() -> ServiceStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check_mongodb(cache: &MongoCache) -> ServiceStatus {
|
|
||||||
let start = Instant::now();
|
|
||||||
match cache.health_check().await {
|
|
||||||
Ok(_) => ServiceStatus {
|
|
||||||
status: "ok".to_string(),
|
|
||||||
latency_ms: Some(start.elapsed().as_millis() as u64),
|
|
||||||
error: None,
|
|
||||||
},
|
|
||||||
Err(e) => ServiceStatus {
|
|
||||||
status: "error".to_string(),
|
|
||||||
latency_ms: Some(start.elapsed().as_millis() as u64),
|
|
||||||
error: Some(e.to_string()),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_required_migrations() -> Vec<MigrationInfo> {
|
fn parse_required_migrations() -> Vec<MigrationInfo> {
|
||||||
let raw = env!("REQUIRED_MIGRATIONS");
|
let raw = env!("REQUIRED_MIGRATIONS");
|
||||||
if raw.is_empty() {
|
if raw.is_empty() {
|
||||||
@@ -631,19 +612,21 @@ async fn check_rsync() -> ServiceStatus {
|
|||||||
|
|
||||||
/// Check worker liveness via Redis health key TTL.
|
/// Check worker liveness via Redis health key TTL.
|
||||||
/// Returns true if the Worker's Redis health key exists and has remaining TTL > 0.
|
/// Returns true if the Worker's Redis health key exists and has remaining TTL > 0.
|
||||||
pub async fn check_worker_alive(state: &AppState) -> bool {
|
pub async fn check_worker_alive(_state: &AppState) -> bool {
|
||||||
let health_key = format!("{}health", crate::core::config::REDIS_KEY_PREFIX.as_str());
|
let health_key = format!("{}health", crate::core::config::REDIS_KEY_PREFIX.as_str());
|
||||||
let client = state.redis_cache.get_client().await;
|
// Use a fresh client (same pattern as check_redis) instead of the shared
|
||||||
let guard = client.write().await;
|
// redis_cache client: the shared client's RwLock can be held indefinitely
|
||||||
if let Ok(mut conn) = guard.get_conn().await {
|
// by a task stalled on redis reconnect, deadlocking every health check.
|
||||||
|
let client = match RedisClient::new() {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(_) => return false,
|
||||||
|
};
|
||||||
|
if let Ok(mut conn) = client.get_conn().await {
|
||||||
let ttl: Result<i64, _> = redis::cmd("TTL")
|
let ttl: Result<i64, _> = redis::cmd("TTL")
|
||||||
.arg(&[health_key.as_str()])
|
.arg(&[health_key.as_str()])
|
||||||
.query_async(&mut conn)
|
.query_async(&mut conn)
|
||||||
.await;
|
.await;
|
||||||
match ttl {
|
return matches!(ttl, Ok(ttl) if ttl > 0);
|
||||||
Ok(ttl) if ttl > 0 => return true,
|
|
||||||
_ => return false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user