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
|
2023-06-11 15:01:50 +02:00
|
|
|
from frigate.models import Event, Recordings, RecordingsToDelete, Timeline
|
2023-04-26 15:25:26 +02:00
|
|
|
from frigate.record.cleanup import RecordingCleanup
|
|
|
|
from frigate.record.maintainer import RecordingMaintainer
|
2023-07-01 15:18:33 +02:00
|
|
|
from frigate.types import FeatureMetricsTypes
|
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__)
|
|
|
|
|
|
|
|
|
|
|
|
def manage_recordings(
|
|
|
|
config: FrigateConfig,
|
2023-07-16 14:42:56 +02:00
|
|
|
object_recordings_info_queue: mp.Queue,
|
|
|
|
audio_recordings_info_queue: mp.Queue,
|
2023-07-01 15:18:33 +02:00
|
|
|
process_info: dict[str, FeatureMetricsTypes],
|
2023-04-26 15:25:26 +02:00
|
|
|
) -> 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
|
|
|
|
},
|
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
|
|
|
)
|
2023-06-11 15:01:50 +02:00
|
|
|
models = [Event, Recordings, Timeline, RecordingsToDelete]
|
2023-04-26 15:25:26 +02:00
|
|
|
db.bind(models)
|
|
|
|
|
|
|
|
maintainer = RecordingMaintainer(
|
2023-07-15 02:05:14 +02:00
|
|
|
config,
|
|
|
|
object_recordings_info_queue,
|
|
|
|
audio_recordings_info_queue,
|
|
|
|
process_info,
|
|
|
|
stop_event,
|
2023-04-26 15:25:26 +02:00
|
|
|
)
|
|
|
|
maintainer.start()
|
|
|
|
|
|
|
|
cleanup = RecordingCleanup(config, stop_event)
|
|
|
|
cleanup.start()
|