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:
parent
de34516fed
commit
2026bf5305
10
src/main.rs
10
src/main.rs
|
|
@ -53,9 +53,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.unwrap_or(DEFAULT_PORT);
|
||||
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...");
|
||||
match test_camera(&config) {
|
||||
match test_camera(&startup_config) {
|
||||
Ok((actual_w, actual_h, frame_size)) => {
|
||||
let conditioned_per_frame = (frame_size / CHUNK_SIZE) * 32;
|
||||
let throughput_30fps = conditioned_per_frame * 30;
|
||||
|
|
@ -76,7 +79,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"Camera error: {}. Requests will fail until camera is available.",
|
||||
"Camera warning: {}. Requests will fail until camera is available.",
|
||||
e
|
||||
);
|
||||
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()
|
||||
.route("/", get(index))
|
||||
|
|
|
|||
Loading…
Reference in New Issue