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:
parent
2026bf5305
commit
b26cd18579
23
src/main.rs
23
src/main.rs
|
|
@ -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!({
|
||||
let body = 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(),
|
||||
}),
|
||||
};
|
||||
"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()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue