Skip to main content

heldar_kernel/services/
schedule_watcher.rs

1//! Recording-schedule watcher. On each tick it asks the recorder to reconcile the time-based
2//! cameras (`scheduled` / `scheduled_event`) whose recording state must change because a window just
3//! opened or closed — so a recorder starts when the window opens and stops when it closes, without
4//! waiting for an external API call. Continuous cameras are untouched (their reconcile is event-driven
5//! on config change), and a camera already in the correct state is never restarted mid-window.
6//!
7//! Schedule windows are evaluated against the SERVER's LOCAL timezone (chrono::Local); there is no
8//! per-camera timezone. Spawned (supervised) from `main` only when the recorder is enabled.
9
10use std::time::Duration;
11
12use crate::state::AppState;
13
14pub async fn run(state: AppState) {
15    let interval_s = state.cfg.schedule_check_interval_s.max(5);
16    let mut tick = tokio::time::interval(Duration::from_secs(interval_s));
17    loop {
18        tick.tick().await;
19        state.recorder.reconcile_schedules().await;
20    }
21}