2023-04-26 07:25:26 -06:00
|
|
|
"""Run recording maintainer and cleanup."""
|
|
|
|
|
|
|
|
|
|
import logging
|
2025-06-24 11:41:11 -06:00
|
|
|
from multiprocessing.synchronize import Event as MpEvent
|
2023-04-26 07:25:26 -06:00
|
|
|
|
|
|
|
|
from playhouse.sqliteq import SqliteQueueDatabase
|
|
|
|
|
|
|
|
|
|
from frigate.config import FrigateConfig
|
2025-07-18 11:23:06 -06:00
|
|
|
from frigate.const import PROCESS_PRIORITY_HIGH
|
2024-09-02 07:22:53 -06:00
|
|
|
from frigate.models import Recordings, ReviewSegment
|
2023-04-26 07:25:26 -06:00
|
|
|
from frigate.record.maintainer import RecordingMaintainer
|
2025-06-13 11:09:51 -06:00
|
|
|
from frigate.util.process import FrigateProcess
|
2023-04-26 07:25:26 -06:00
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
2025-06-12 12:12:34 -06:00
|
|
|
class RecordProcess(FrigateProcess):
|
2025-06-24 11:41:11 -06:00
|
|
|
def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
|
2025-07-18 11:23:06 -06:00
|
|
|
super().__init__(
|
|
|
|
|
stop_event,
|
|
|
|
|
PROCESS_PRIORITY_HIGH,
|
|
|
|
|
name="frigate.recording_manager",
|
|
|
|
|
daemon=True,
|
|
|
|
|
)
|
2025-06-12 12:12:34 -06:00
|
|
|
self.config = config
|
2023-04-26 07:25:26 -06:00
|
|
|
|
2025-06-12 12:12:34 -06:00
|
|
|
def run(self) -> None:
|
2025-06-13 09:43:38 -05:00
|
|
|
self.pre_run_setup(self.config.logger)
|
2025-06-12 12:12:34 -06:00
|
|
|
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)
|
2023-04-26 07:25:26 -06:00
|
|
|
|
2025-06-12 12:12:34 -06:00
|
|
|
maintainer = RecordingMaintainer(
|
|
|
|
|
self.config,
|
|
|
|
|
self.stop_event,
|
|
|
|
|
)
|
|
|
|
|
maintainer.start()
|