Add expire interval option for snaphots

This commit is contained in:
Nick Mowen 2022-10-07 09:36:31 -06:00
parent 7c60753ab0
commit b8311071f2
2 changed files with 18 additions and 10 deletions

View File

@ -440,6 +440,10 @@ class CameraFfmpegConfig(FfmpegConfig):
class SnapshotsConfig(FrigateBaseModel):
enabled: bool = Field(default=False, title="Snapshots enabled.")
expire_interval: int = Field(
default=5,
title="Number of minutes to wait between cleanup runs.",
)
clean_copy: bool = Field(
default=True, title="Create a clean copy of the snapshot image."
)

View File

@ -1,4 +1,5 @@
import datetime
import itertools
import logging
import os
import queue
@ -289,7 +290,12 @@ class EventCleanup(threading.Thread):
def run(self):
# only expire events every 5 minutes
while not self.stop_event.wait(300):
for counter in itertools.cycle(range(self.config.snapshots.expire_interval)):
if self.stop_event.wait(60):
logger.info(f"Exiting event cleanup...")
break
if counter == 0:
self.expire("clips")
self.expire("snapshots")
self.purge_duplicates()
@ -299,5 +305,3 @@ class EventCleanup(threading.Thread):
Event.has_clip == False, Event.has_snapshot == False
)
delete_query.execute()
logger.info(f"Exiting event cleanup...")