Handle recording checks in utc (#8379)

* Handle recording checks in utc

* Formatting
This commit is contained in:
Nicolas Mowen 2023-10-30 18:25:21 -06:00 committed by GitHub
parent 9d717b371c
commit e89dafa82e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -260,8 +260,10 @@ class RecordingMaintainer(threading.Thread):
most_recently_processed_frame_time = (
camera_info[-1][0] if len(camera_info) > 0 else 0
)
retain_cutoff = most_recently_processed_frame_time - pre_capture
if end_time.timestamp() < retain_cutoff:
retain_cutoff = datetime.datetime.fromtimestamp(
most_recently_processed_frame_time - pre_capture
).astimezone(datetime.timezone.utc)
if end_time.astimezone(datetime.timezone.utc) < retain_cutoff:
Path(cache_path).unlink(missing_ok=True)
self.end_time_cache.pop(cache_path, None)
# else retain days includes this segment
@ -273,7 +275,11 @@ class RecordingMaintainer(threading.Thread):
)
# ensure delayed segment info does not lead to lost segments
if most_recently_processed_frame_time >= end_time.timestamp():
if datetime.datetime.fromtimestamp(
most_recently_processed_frame_time
).astimezone(datetime.timezone.utc) >= end_time.astimezone(
datetime.timezone.utc
):
record_mode = self.config.cameras[camera].record.retain.mode
return await self.move_segment(
camera, start_time, end_time, duration, cache_path, record_mode

View File

@ -233,14 +233,15 @@ class CameraWatchdog(threading.Thread):
poll = p["process"].poll()
if self.config.record.enabled and "record" in p["roles"]:
latest_segment_time = self.get_latest_segment_timestamp(
latest_segment_time = self.get_latest_segment_datetime(
p.get(
"latest_segment_time", datetime.datetime.now().timestamp()
"latest_segment_time",
datetime.datetime.now().astimezone(datetime.timezone.utc),
)
)
if datetime.datetime.now().timestamp() > (
latest_segment_time + 120
if datetime.datetime.now().astimezone(datetime.timezone.utc) > (
latest_segment_time + datetime.timedelta(seconds=120)
):
self.logger.error(
f"No new recording segments were created for {self.camera_name} in the last 120s. restarting the ffmpeg record process..."
@ -288,7 +289,7 @@ class CameraWatchdog(threading.Thread):
)
self.capture_thread.start()
def get_latest_segment_timestamp(self, latest_timestamp) -> int:
def get_latest_segment_datetime(self, latest_segment: datetime.datetime) -> int:
"""Checks if ffmpeg is still writing recording segments to cache."""
cache_files = sorted(
[
@ -299,13 +300,15 @@ class CameraWatchdog(threading.Thread):
and not d.startswith("clip_")
]
)
newest_segment_timestamp = latest_timestamp
newest_segment_timestamp = latest_segment
for file in cache_files:
if self.camera_name in file:
basename = os.path.splitext(file)[0]
_, date = basename.rsplit("-", maxsplit=1)
ts = datetime.datetime.strptime(date, "%Y%m%d%H%M%S").timestamp()
ts = datetime.datetime.strptime(date, "%Y%m%d%H%M%S").astimezone(
datetime.timezone.utc
)
if ts > newest_segment_timestamp:
newest_segment_timestamp = ts