From 06b08e1a7746e7d4c66910e7105ccf3359296194 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Tue, 25 Apr 2023 09:04:53 -0600 Subject: [PATCH] Mypy fixes --- frigate/record/cleanup.py | 15 +++++++++------ frigate/record/maintainer.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py index 4ea3015b2..74c7eadf2 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -8,6 +8,7 @@ import threading from pathlib import Path from peewee import DoesNotExist +from multiprocessing.synchronize import Event as MpEvent from frigate.config import RetainModeEnum, FrigateConfig from frigate.const import RECORD_DIR, SECONDS_IN_DAY @@ -18,13 +19,15 @@ logger = logging.getLogger(__name__) class RecordingCleanup(threading.Thread): - def __init__(self, config: FrigateConfig, stop_event): + """Cleanup existing recordings based on retention config.""" + + def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None: threading.Thread.__init__(self) self.name = "recording_cleanup" self.config = config self.stop_event = stop_event - def clean_tmp_clips(self): + def clean_tmp_clips(self) -> None: # delete any clips more than 5 minutes old for p in Path("/tmp/cache").rglob("clip_*.mp4"): logger.debug(f"Checking tmp clip {p}.") @@ -36,7 +39,7 @@ class RecordingCleanup(threading.Thread): pass p.unlink(missing_ok=True) - def expire_recordings(self): + def expire_recordings(self) -> None: logger.debug("Start expire recordings (new).") logger.debug("Start deleted cameras.") @@ -151,7 +154,7 @@ class RecordingCleanup(threading.Thread): logger.debug("End all cameras.") logger.debug("End expire recordings (new).") - def expire_files(self): + def expire_files(self) -> None: logger.debug("Start expire files (legacy).") default_expire = ( @@ -197,7 +200,7 @@ class RecordingCleanup(threading.Thread): logger.debug("End expire files (legacy).") - def sync_recordings(self): + def sync_recordings(self) -> None: logger.debug("Start sync recordings.") # get all recordings in the db @@ -228,7 +231,7 @@ class RecordingCleanup(threading.Thread): logger.debug("End sync recordings.") - def run(self): + def run(self) -> None: # on startup sync recordings with disk (disabled due to too much CPU usage) # self.sync_recordings() diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index fd9846e56..974dd3495 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -9,11 +9,12 @@ import random import string import subprocess as sp import threading -from collections import defaultdict -from pathlib import Path - import psutil +from collections import defaultdict +from multiprocessing.synchronize import Event as MpEvent +from pathlib import Path + from frigate.config import RetainModeEnum, FrigateConfig from frigate.const import CACHE_DIR, MAX_SEGMENT_DURATION, RECORD_DIR from frigate.models import Event, Recordings @@ -23,8 +24,12 @@ logger = logging.getLogger(__name__) class RecordingMaintainer(threading.Thread): + def __init__( - self, config: FrigateConfig, recordings_info_queue: mp.Queue, stop_event + self, + config: FrigateConfig, + recordings_info_queue: mp.Queue, + stop_event: MpEvent, ): threading.Thread.__init__(self) self.name = "recording_maint"