From b26cd18579d2d0a7e2442a3fd7943f6a77fb9542 Mon Sep 17 00:00:00 2001 From: Leopere Date: Sun, 15 Feb 2026 11:53:14 -0500 Subject: [PATCH] Make health endpoint lightweight (no camera open) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Health check no longer opens the camera — it just confirms the server is running. This prevents blocking when the camera is in use by a concurrent request or the background startup test. Co-authored-by: Cursor --- src/main.rs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5a3dfe4..45678e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,25 +143,14 @@ async fn main() -> Result<(), Box> { async fn index() -> Html<&'static str> { Html(INDEX_HTML) } async fn tools_page() -> Html<&'static str> { Html(TOOLS_HTML) } -/// Health check: tests camera access right now. Camera must be reachable. +/// Health check: lightweight probe — confirms the server is running. +/// Actual camera availability is tested on every /random request. async fn health() -> Response { - let config = CameraConfig::from_env(); - let result = tokio::task::spawn_blocking(move || test_camera(&config)).await; - let body = match result { - Ok(Ok((w, h, frame_size))) => serde_json::json!({ - "status": "ok", - "camera": format!("{}x{}", w, h), - "frame_bytes": frame_size, - }), - Ok(Err(e)) => serde_json::json!({ - "status": "error", - "error": e, - }), - Err(e) => serde_json::json!({ - "status": "error", - "error": e.to_string(), - }), - }; + let body = serde_json::json!({ + "status": "ok", + "mode": "live", + "note": "Camera is opened on each request. Hit /random to test live capture.", + }); Response::builder() .header(header::CONTENT_TYPE, "application/json") .body(Body::from(body.to_string()))