Skip to content

Commit

Permalink
Merge pull request #853 from roflcoopter/feature/wait-for-move-on-shu…
Browse files Browse the repository at this point in the history
…tdown

wait for move_on_shutdown to complete
  • Loading branch information
roflcoopter authored Dec 11, 2024
2 parents 37b5a1e + 3cf414b commit f46e7e7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions viseron/components/storage/tier_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
get_recorder_path,
)
from viseron.components.webserver.const import COMPONENT as WEBSERVER_COMPONENT
from viseron.const import CAMERA_SEGMENT_DURATION, VISERON_SIGNAL_LAST_WRITE
from viseron.const import (
CAMERA_SEGMENT_DURATION,
VISERON_SIGNAL_LAST_WRITE,
VISERON_SIGNAL_STOPPING,
)
from viseron.domains.camera import FailedCamera
from viseron.domains.camera.const import CONFIG_RECORDER, CONFIG_RETAIN
from viseron.helpers import utcnow
Expand Down Expand Up @@ -108,6 +112,7 @@ def __init__(

self.initialize()
vis.register_signal_handler(VISERON_SIGNAL_LAST_WRITE, self._shutdown)
vis.register_signal_handler(VISERON_SIGNAL_STOPPING, self._stop_observer)

self._pending_updates: dict[str, Timer] = {}
self._event_queue: Queue[FileSystemEvent | None] = Queue()
Expand Down Expand Up @@ -342,7 +347,7 @@ def _on_deleted(self, event: FileDeletedEvent) -> None:

def _shutdown(self) -> None:
"""Shutdown the observer and event handler."""
self._logger.debug("Stopping observer")
self._logger.debug("Initiating observer shutdown")
if self._tier[CONFIG_MOVE_ON_SHUTDOWN]:
self._logger.debug("Forcing move of files")
force_move_files(
Expand All @@ -356,6 +361,10 @@ def _shutdown(self) -> None:
self._next_tier,
self._logger,
)

def _stop_observer(self) -> None:
"""Stop the observer."""
self._logger.debug("Stopping observer")
for pending_update in self._pending_updates.copy().values():
pending_update.join()
self._event_queue.put(None)
Expand Down

0 comments on commit f46e7e7

Please sign in to comment.