blakeblackshear.frigate/frigate/record/record.py
Nicolas Mowen 542bf05bb8 Handle SIGINT with forkserver (#18860)
* Pass stopevent from main start

* Share stop event across processes

* preload modules

* remove explicit os._exit call

---------

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
2025-08-16 10:20:33 -05:00

42 lines
1.4 KiB
Python

"""Run recording maintainer and cleanup."""
import logging
from multiprocessing.synchronize import Event as MpEvent
from playhouse.sqliteq import SqliteQueueDatabase
from frigate.config import FrigateConfig
from frigate.models import Recordings, ReviewSegment
from frigate.record.maintainer import RecordingMaintainer
from frigate.util.process import FrigateProcess
logger = logging.getLogger(__name__)
class RecordProcess(FrigateProcess):
def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
super().__init__(stop_event, name="frigate.recording_manager", daemon=True)
self.config = config
def run(self) -> None:
self.pre_run_setup(self.config.logger)
db = SqliteQueueDatabase(
self.config.database.path,
pragmas={
"auto_vacuum": "FULL", # Does not defragment database
"cache_size": -512 * 1000, # 512MB of cache
"synchronous": "NORMAL", # Safe when using WAL https://www.sqlite.org/pragma.html#pragma_synchronous
},
timeout=max(
60, 10 * len([c for c in self.config.cameras.values() if c.enabled])
),
)
models = [ReviewSegment, Recordings]
db.bind(models)
maintainer = RecordingMaintainer(
self.config,
self.stop_event,
)
maintainer.start()