Expand description
Small shared data-access helpers used by background services and routes.
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
lockedread-lock). Whenincident_idis supplied it is recorded;COALESCEpreserves any existing tag whenincident_idisNone(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
stateandlast_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.