better cache handling

This commit is contained in:
Blake Blackshear 2021-11-17 08:57:57 -06:00
parent 7533f2a8ab
commit ba55b5a6db

View File

@ -88,15 +88,9 @@ class RecordingMaintainer(threading.Thread):
} }
) )
# delete all cached files past the most recent 2, but not on the first check # delete all cached files past the most recent 2
if self.first_pass:
self.first_pass = False
else:
for camera in grouped_recordings.keys(): for camera in grouped_recordings.keys():
if len(grouped_recordings[camera]) > 2: if len(grouped_recordings[camera]) > 2:
logger.warning(
"Proactively cleaning cache. Your recordings disk may be too slow."
)
sorted_recordings = sorted( sorted_recordings = sorted(
grouped_recordings[camera], key=lambda i: i["start_time"] grouped_recordings[camera], key=lambda i: i["start_time"]
) )
@ -182,8 +176,6 @@ class RecordingMaintainer(threading.Thread):
duration, duration,
cache_path, cache_path,
) )
else:
Path(cache_path).unlink(missing_ok=True)
# else retain_days includes this segment # else retain_days includes this segment
else: else:
self.store_segment( self.store_segment(
@ -236,7 +228,14 @@ class RecordingMaintainer(threading.Thread):
"Error occurred when attempting to maintain recording cache" "Error occurred when attempting to maintain recording cache"
) )
logger.error(e) logger.error(e)
wait_time = max(0, 5 - (datetime.datetime.now().timestamp() - run_start)) duration = datetime.datetime.now().timestamp() - run_start
wait_time = max(0, 5 - duration)
if duration > 10 and not self.first_pass:
logger.warning(
"Cache maintenance is taking longer than 10 seconds to clear. Your recordings disk may be too slow."
)
if self.first_pass:
self.first_pass = False
logger.info(f"Exiting recording maintenance...") logger.info(f"Exiting recording maintenance...")