2023-04-26 15:25:26 +02:00
|
|
|
"""Run recording maintainer and cleanup."""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import multiprocessing as mp
|
|
|
|
import signal
|
|
|
|
import threading
|
|
|
|
from types import FrameType
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from playhouse.sqliteq import SqliteQueueDatabase
|
2023-05-29 12:31:17 +02:00
|
|
|
from setproctitle import setproctitle
|
2023-04-26 15:25:26 +02:00
|
|
|
|
|
|
|
from frigate.config import FrigateConfig
|
2024-09-02 15:22:53 +02:00
|
|
|
from frigate.models import Recordings, ReviewSegment
|
2023-04-26 15:25:26 +02:00
|
|
|
from frigate.record.maintainer import RecordingMaintainer
|
2023-07-06 16:28:50 +02:00
|
|
|
from frigate.util.services import listen
|
2023-04-26 15:25:26 +02:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2024-02-19 14:26:59 +01:00
|
|
|
def manage_recordings(config: FrigateConfig) -> None:
|
2023-04-26 15:25:26 +02:00
|
|
|
stop_event = mp.Event()
|
|
|
|
|
|
|
|
def receiveSignal(signalNumber: int, frame: Optional[FrameType]) -> None:
|
2024-06-07 01:54:38 +02:00
|
|
|
logger.debug(f"Recording manager process received signal {signalNumber}")
|
2023-04-26 15:25:26 +02:00
|
|
|
stop_event.set()
|
|
|
|
|
|
|
|
signal.signal(signal.SIGTERM, receiveSignal)
|
|
|
|
signal.signal(signal.SIGINT, receiveSignal)
|
|
|
|
|
|
|
|
threading.current_thread().name = "process:recording_manager"
|
|
|
|
setproctitle("frigate.recording_manager")
|
|
|
|
listen()
|
|
|
|
|
2023-06-11 14:23:18 +02:00
|
|
|
db = SqliteQueueDatabase(
|
|
|
|
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
|
|
|
|
},
|
2023-07-21 14:29:50 +02:00
|
|
|
timeout=max(60, 10 * len([c for c in config.cameras.values() if c.enabled])),
|
2023-06-11 14:23:18 +02:00
|
|
|
)
|
2024-09-02 15:22:53 +02:00
|
|
|
models = [ReviewSegment, Recordings]
|
2023-04-26 15:25:26 +02:00
|
|
|
db.bind(models)
|
|
|
|
|
|
|
|
maintainer = RecordingMaintainer(
|
2023-07-15 02:05:14 +02:00
|
|
|
config,
|
|
|
|
stop_event,
|
2023-04-26 15:25:26 +02:00
|
|
|
)
|
|
|
|
maintainer.start()
|