release: v1.3.5 - merge Phase 1 (health/queue API + timeout_at self-heal) onto v1.3.4 base

- Add /api/v1/health/queue queue-health endpoint (public, like /health/detailed)
- Add timeout_at column + index (migration 20261012_add_command_timeout.sql)
- consume() stamps timeout_at; pipeline_worker self-heals timed-out commands every 5m
- Bump version 1.3.4 -> 1.3.5
This commit is contained in:
Accusys
2026-10-13 00:12:05 +08:00
parent dc6081fcaf
commit 667e279768
11 changed files with 475 additions and 5 deletions
+78
View File
@@ -700,9 +700,87 @@ async fn check_http(url: &str) -> ServiceStatus {
}
}
#[derive(Debug, Serialize)]
pub struct QueueHealth {
pub status: String,
pub stuck_commands: i64,
pub pending_commands: i64,
pub processing_commands: i64,
pub completed_last_hour: i64,
pub failed_last_hour: i64,
pub avg_processing_time_ms: Option<f64>,
}
pub async fn check_queue_health(pool: &sqlx::PgPool) -> Result<QueueHealth, sqlx::Error> {
let stuck_commands: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM command_queue
WHERE status = 'processing'
AND processing_started_at < NOW() - INTERVAL '1 hour'",
)
.fetch_one(pool)
.await?;
let pending_commands: i64 =
sqlx::query_scalar("SELECT COUNT(*) FROM command_queue WHERE status = 'pending'")
.fetch_one(pool)
.await?;
let processing_commands: i64 =
sqlx::query_scalar("SELECT COUNT(*) FROM command_queue WHERE status = 'processing'")
.fetch_one(pool)
.await?;
let completed_last_hour: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM command_queue
WHERE status = 'completed'
AND processing_completed_at > NOW() - INTERVAL '1 hour'",
)
.fetch_one(pool)
.await?;
let failed_last_hour: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM command_queue
WHERE status = 'failed'
AND processing_completed_at > NOW() - INTERVAL '1 hour'",
)
.fetch_one(pool)
.await?;
let avg_processing_time_ms: Option<f64> = sqlx::query_scalar(
"SELECT AVG(EXTRACT(EPOCH FROM (processing_completed_at - processing_started_at)) * 1000)::double precision
FROM command_queue
WHERE status = 'completed'
AND processing_completed_at > NOW() - INTERVAL '1 hour'",
)
.fetch_one(pool)
.await?;
let status = if stuck_commands > 0 { "unhealthy" } else { "healthy" };
Ok(QueueHealth {
status: status.to_string(),
stuck_commands,
pending_commands,
processing_commands,
completed_last_hour,
failed_last_hour,
avg_processing_time_ms,
})
}
pub async fn health_queue(
State(state): State<AppState>,
) -> Result<Json<QueueHealth>, (StatusCode, String)> {
match check_queue_health(state.db.pool()).await {
Ok(health) => Ok(Json(health)),
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
pub fn health_routes() -> Router<AppState> {
Router::new()
.route("/health", get(health))
.route("/health/detailed", get(health_detailed))
.route("/health/consistency", get(health_consistency))
.route("/health/queue", get(health_queue))
}
+5 -1
View File
@@ -20,7 +20,7 @@ use super::docs;
use super::face_filter;
use super::files;
use super::health;
use super::health::{health, health_consistency, health_detailed};
use super::health::{health, health_consistency, health_detailed, health_queue};
use super::identities;
use super::identity_api;
use super::identity_binding;
@@ -173,6 +173,10 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
.route(
"/api/v1/health/consistency",
axum::routing::get(health_consistency),
)
.route(
"/api/v1/health/queue",
axum::routing::get(health_queue),
);
let app = Router::new()