Move startup camera test to background thread

Server starts accepting requests immediately instead of blocking on
the camera test. If the camera lock is held by a previous process,
the server is still reachable and will attempt live camera access
on each request independently.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leopere 2026-02-15 11:49:37 -05:00
parent de34516fed
commit 2026bf5305
Signed by: colin
SSH Key Fingerprint: SHA256:nRPCQTeMFLdGytxRQmPVK9VXY3/ePKQ5lGRyJhT5DY8
1 changed files with 34 additions and 30 deletions

View File

@ -53,9 +53,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap_or(DEFAULT_PORT); .unwrap_or(DEFAULT_PORT);
let config = CameraConfig::from_env(); let config = CameraConfig::from_env();
// Test camera access at startup (informational only). // Test camera access at startup (informational only, non-blocking).
// Server starts immediately; the camera test runs in the background.
let startup_config = config.clone();
std::thread::spawn(move || {
println!("Testing camera access..."); println!("Testing camera access...");
match test_camera(&config) { match test_camera(&startup_config) {
Ok((actual_w, actual_h, frame_size)) => { Ok((actual_w, actual_h, frame_size)) => {
let conditioned_per_frame = (frame_size / CHUNK_SIZE) * 32; let conditioned_per_frame = (frame_size / CHUNK_SIZE) * 32;
let throughput_30fps = conditioned_per_frame * 30; let throughput_30fps = conditioned_per_frame * 30;
@ -76,7 +79,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
Err(e) => { Err(e) => {
eprintln!( eprintln!(
"Camera error: {}. Requests will fail until camera is available.", "Camera warning: {}. Requests will fail until camera is available.",
e e
); );
if e.contains("Lock Rejected") || e.contains("lock") { if e.contains("Lock Rejected") || e.contains("lock") {
@ -86,6 +89,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
} }
} }
});
let app = Router::new() let app = Router::new()
.route("/", get(index)) .route("/", get(index))