switch to retain config instead of retain_days

This commit is contained in:
Blake Blackshear 2021-12-11 09:22:44 -06:00
parent 63f8034e46
commit 9f18629df3
2 changed files with 34 additions and 8 deletions

View File

@ -65,8 +65,17 @@ class MqttConfig(FrigateBaseModel):
return v return v
class RetainModeEnum(str, Enum):
all = "all"
motion = "motion"
active_objects = "active_objects"
class RetainConfig(FrigateBaseModel): class RetainConfig(FrigateBaseModel):
default: float = Field(default=10, title="Default retention period.") default: float = Field(default=10, title="Default retention period.")
mode: RetainModeEnum = Field(
default=RetainModeEnum.active_objects, title="Retain mode."
)
objects: Dict[str, float] = Field( objects: Dict[str, float] = Field(
default_factory=dict, title="Object retention period." default_factory=dict, title="Object retention period."
) )
@ -88,9 +97,18 @@ class EventsConfig(FrigateBaseModel):
) )
class RecordRetainConfig(FrigateBaseModel):
days: float = Field(default=0, title="Default retention period.")
mode: RetainModeEnum = Field(default=RetainModeEnum.all, title="Retain mode.")
class RecordConfig(FrigateBaseModel): class RecordConfig(FrigateBaseModel):
enabled: bool = Field(default=False, title="Enable record on all cameras.") enabled: bool = Field(default=False, title="Enable record on all cameras.")
retain_days: float = Field(default=0, title="Recording retention period in days.") # deprecated - to be removed in a future version
retain_days: Optional[float] = Field(title="Recording retention period in days.")
retain: RecordRetainConfig = Field(
default_factory=RecordRetainConfig, title="Record retention settings."
)
events: EventsConfig = Field( events: EventsConfig = Field(
default_factory=EventsConfig, title="Event specific settings." default_factory=EventsConfig, title="Event specific settings."
) )
@ -810,6 +828,14 @@ class FrigateConfig(FrigateBaseModel):
f"Camera {name} has rtmp enabled, but rtmp is not assigned to an input." f"Camera {name} has rtmp enabled, but rtmp is not assigned to an input."
) )
# backwards compatibility for retain_days
if not camera_config.record.retain_days is None:
logger.warning(
"The 'retain_days' config option has been DEPRECATED and will be removed in a future version. Please use the 'days' setting under 'retain'"
)
if camera_config.record.retain.days == 0:
camera_config.record.retain.days = camera_config.record.retain_days
config.cameras[name] = camera_config config.cameras[name] = camera_config
return config return config

View File

@ -165,12 +165,12 @@ class RecordingMaintainer(threading.Thread):
Path(cache_path).unlink(missing_ok=True) Path(cache_path).unlink(missing_ok=True)
continue continue
# if cached file's start_time is earlier than the retain_days for the camera # if cached file's start_time is earlier than the retain days for the camera
if start_time <= ( if start_time <= (
( (
datetime.datetime.now() datetime.datetime.now()
- datetime.timedelta( - datetime.timedelta(
days=self.config.cameras[camera].record.retain_days days=self.config.cameras[camera].record.retain.days
) )
) )
): ):
@ -203,7 +203,7 @@ class RecordingMaintainer(threading.Thread):
duration, duration,
cache_path, cache_path,
) )
# else retain_days includes this segment # else retain days includes this segment
else: else:
self.store_segment( self.store_segment(
camera, start_time, end_time, duration, cache_path camera, start_time, end_time, duration, cache_path
@ -314,7 +314,7 @@ class RecordingCleanup(threading.Thread):
logger.debug("Start deleted cameras.") logger.debug("Start deleted cameras.")
# Handle deleted cameras # Handle deleted cameras
expire_days = self.config.record.retain_days expire_days = self.config.record.retain.days
expire_before = ( expire_before = (
datetime.datetime.now() - datetime.timedelta(days=expire_days) datetime.datetime.now() - datetime.timedelta(days=expire_days)
).timestamp() ).timestamp()
@ -340,7 +340,7 @@ class RecordingCleanup(threading.Thread):
datetime.datetime.now() datetime.datetime.now()
- datetime.timedelta(seconds=config.record.events.max_seconds) - datetime.timedelta(seconds=config.record.events.max_seconds)
).timestamp() ).timestamp()
expire_days = config.record.retain_days expire_days = config.record.retain.days
expire_before = ( expire_before = (
datetime.datetime.now() - datetime.timedelta(days=expire_days) datetime.datetime.now() - datetime.timedelta(days=expire_days)
).timestamp() ).timestamp()
@ -416,14 +416,14 @@ class RecordingCleanup(threading.Thread):
default_expire = ( default_expire = (
datetime.datetime.now().timestamp() datetime.datetime.now().timestamp()
- SECONDS_IN_DAY * self.config.record.retain_days - SECONDS_IN_DAY * self.config.record.retain.days
) )
delete_before = {} delete_before = {}
for name, camera in self.config.cameras.items(): for name, camera in self.config.cameras.items():
delete_before[name] = ( delete_before[name] = (
datetime.datetime.now().timestamp() datetime.datetime.now().timestamp()
- SECONDS_IN_DAY * camera.record.retain_days - SECONDS_IN_DAY * camera.record.retain.days
) )
# find all the recordings older than the oldest recording in the db # find all the recordings older than the oldest recording in the db