Make health endpoint lightweight (no camera open)

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 <cursoragent@cursor.com>
This commit is contained in:
Leopere 2026-02-15 11:53:14 -05:00
parent 2026bf5305
commit b26cd18579
Signed by: colin
SSH Key Fingerprint: SHA256:nRPCQTeMFLdGytxRQmPVK9VXY3/ePKQ5lGRyJhT5DY8
1 changed files with 7 additions and 18 deletions

View File

@ -143,25 +143,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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()))