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
|
|
|
|
from frigate.models import Event, Recordings, Timeline
|
|
|
|
from frigate.record.cleanup import RecordingCleanup
|
|
|
|
from frigate.record.maintainer import RecordingMaintainer
|
|
|
|
from frigate.types import RecordMetricsTypes
|
|
|
|
from frigate.util import listen
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def manage_recordings(
|
|
|
|
config: FrigateConfig,
|
|
|
|
recordings_info_queue: mp.Queue,
|
|
|
|
process_info: dict[str, RecordMetricsTypes],
|
|
|
|
) -> None:
|
|
|
|
stop_event = mp.Event()
|
|
|
|
|
|
|
|
def receiveSignal(signalNumber: int, frame: Optional[FrameType]) -> None:
|
|
|
|
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
|
|
|
|
},
|
|
|
|
timeout=60,
|
|
|
|
)
|
2023-04-26 15:25:26 +02:00
|
|
|
models = [Event, Recordings, Timeline]
|
|
|
|
db.bind(models)
|
|
|
|
|
|
|
|
maintainer = RecordingMaintainer(
|
|
|
|
config, recordings_info_queue, process_info, stop_event
|
|
|
|
)
|
|
|
|
maintainer.start()
|
|
|
|
|
|
|
|
cleanup = RecordingCleanup(config, stop_event)
|
|
|
|
cleanup.start()
|