Skip to main content

Module repo

Module repo 

Source
Expand description

Small shared data-access helpers used by background services and routes.

Structs§

SegReadLock
RAII read-lock over a set of segments. acquire sets locked = 1; Drop releases it best-effort even if the holder is cancelled (e.g. the HTTP client disconnects and the handler future is dropped) or panics — so an interrupted export never leaves footage permanently un-prunable. Drop can’t await, so it spawns the release; the startup clear_segment_read_locks is the backstop if that spawn can’t finish.

Functions§

bump_reconnect
Increment the reconnect counter, clear pid, and record the last error.
log_event
Insert an event into the event log.
record_segment_indexed
Record that a new segment was indexed: bump count, set last_segment_at and observed bitrate.
set_evidence_locked
Set or clear the DURABLE evidence lock on a single segment (distinct from the transient locked read-lock). When incident_id is supplied it is recorded; COALESCE preserves any existing tag when incident_id is None (so unlocking — or locking without a tag — never erases the case the segment was already attached to). Returns the number of rows affected (0 ⇒ no such segment).
set_running
Mark the recorder process started: set state, pid, and last_started_at.
set_segments_locked
Toggle a transient read-lock on a set of segments so the retention sweeper (which only deletes locked = 0) won’t remove them while clip/snapshot ffmpeg is reading them — closing the TOCTOU between selecting segments and ffmpeg opening their files. Best-effort: a failure is logged, not fatal (the read still proceeds). Locks are cleared at startup (crate::db::clear_segment_read_locks) so a crash mid-read cannot pin segments forever.
set_state
Upsert the camera status row, setting state and last_error (does not touch counters).
upsert_recording_gap
Record a detected recording gap (a hole > 3s between consecutive segments) for ANR re-fill. Ignore-on-conflict by (camera_id, gap_start) so re-scans never duplicate a gap. Best-effort: a failure is the caller’s to log, not fatal to indexing.