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:
Accusys
2026-11-08 23:24:02 +08:00
parent c6cbb5d1fb
commit 4f4aa27da8
+15 -32
View File
@@ -4,7 +4,6 @@ use serde::Serialize;
use std::time::Instant;
use super::types::AppState;
use crate::core::cache::MongoCache;
use crate::core::config;
use crate::core::db::{Database, PostgresDb, RedisClient};
use crate::core::db::qdrant_db::new_http_client;
@@ -181,7 +180,7 @@ struct ServiceHealth {
postgres: ServiceStatus,
redis: ServiceStatus,
qdrant: ServiceStatus,
mongodb: ServiceStatus,
// mongodb: ServiceStatus, // Removed - now using Redis only
}
#[derive(Debug, Serialize)]
@@ -195,12 +194,11 @@ pub async fn health(State(state): State<AppState>) -> Json<HealthResponse> {
let postgres = check_postgres().await;
let redis = check_redis().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"
&& redis.status == "ok"
&& qdrant.status == "ok"
&& mongodb.status == "ok";
&& qdrant.status == "ok";
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 redis = check_redis().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"
&& redis.status == "ok"
&& qdrant.status == "ok"
&& mongodb.status == "ok"
{
"ok"
} else {
@@ -339,7 +336,7 @@ pub async fn health_detailed(State(state): State<AppState>) -> Json<DetailedHeal
postgres,
redis,
qdrant,
mongodb,
// mongodb, // Removed
},
resources: ResourceStatus {
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> {
let raw = env!("REQUIRED_MIGRATIONS");
if raw.is_empty() {
@@ -631,19 +612,21 @@ async fn check_rsync() -> ServiceStatus {
/// Check worker liveness via Redis health key TTL.
/// 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 client = state.redis_cache.get_client().await;
let guard = client.write().await;
if let Ok(mut conn) = guard.get_conn().await {
// Use a fresh client (same pattern as check_redis) instead of the shared
// redis_cache client: the shared client's RwLock can be held indefinitely
// 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")
.arg(&[health_key.as_str()])
.query_async(&mut conn)
.await;
match ttl {
Ok(ttl) if ttl > 0 => return true,
_ => return false,
}
return matches!(ttl, Ok(ttl) if ttl > 0);
}
false
}