strix

A simple web UI for motion
git clone https://www.brianlane.com/git/strix
Log | Files | Refs | LICENSE

commit e00a4cf71df69eba1eab8c388c1d2947b705b5d6
parent c5e19f7a1157a6bdda1f9db692f7c7d4eafa5a08
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Wed, 29 Jun 2022 06:04:28 -0700

Fix event expire

It was expiring whole days, not just the events within the day that were
old. IIRC I did this because I was having problems with colliding events
in the initial implementation, but this left some events in the cache
that were deleted from disk.

This fixes it to move each individual event to a camera + date specific
delete directory to prevent collision and only expire the events that
are old.

Diffstat:
Msrc/strix/events.py | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/strix/events.py b/src/strix/events.py @@ -141,7 +141,10 @@ class EventCacheClass: if len(remove) == 0: return - self.log_info(f"Removing {len(remove)} directories") + # The result of the above is a dict (remove) with daily lists of events to be + # removed. NOTE that this may not be ALL the day's events so it needs to move + # them individually, but needs to use the Camera and date to prevent collisions + # with other cameras while waiting for the delete to run in the background. # Create the temporary delete_queue directory delete_queue = tempfile.mkdtemp(dir=os.path.join(self._base_dir, "delete_queue")) @@ -154,16 +157,19 @@ class EventCacheClass: self.log_error(f"Camera* missing from path {daypath}") if cm and os.path.exists(daypath): - self.log_info("REMOVE: %s", daypath) + # Make a directory for the day's events + daydir = os.path.basename(daypath) + dqdir = os.path.join(delete_queue, cm.group(), daydir) + if not os.path.exists(dqdir): + os.makedirs(dqdir) - if not os.path.exists(os.path.join(delete_queue, cm.group())): - os.makedirs(os.path.join(delete_queue, cm.group())) - - # Move the daily directory tree into the delete_queue/Camera* directory - shutil.move(daypath, os.path.join(delete_queue, cm.group())) + # Move the expired events into the delete_queue/Camera*/YYYY-MM-DD/ directory + for e in remove[daypath]: + self.log_info(f"MOVE: {e} -> {dqdir}") + shutil.move(e, dqdir) # Remove the events from the cache - self.log_info(f"Removing {len(remove[daypath])} events") + self.log_info(f"Removing {len(remove[daypath])} events from {daypath}") for e in remove[daypath]: del self._cache[e]