From ad1f5ae08163d9ec2c0f00fa5713a821c5552618 Mon Sep 17 00:00:00 2001 From: Trenton Holmes Date: Tue, 9 Aug 2022 18:20:47 -0700 Subject: [PATCH] Corrects the timeout's interaction with files waiting to be consumed --- .../management/commands/document_consumer.py | 11 ++++++++++- src/documents/tests/test_management_consumer.py | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/documents/management/commands/document_consumer.py b/src/documents/management/commands/document_consumer.py index 1b232c072..3a3b8a163 100644 --- a/src/documents/management/commands/document_consumer.py +++ b/src/documents/management/commands/document_consumer.py @@ -248,7 +248,7 @@ class Command(BaseCommand): while not finished: try: - for event in inotify.read(timeout): + for event in inotify.read(timeout=timeout): if recursive: path = inotify.get_path(event.wd) else: @@ -281,6 +281,15 @@ class Command(BaseCommand): # These files are still waiting to hit the timeout notified_files = still_waiting + # If files are waiting, need to exit read() to check them + # Otherwise, go back to infinite sleep time, but only if not testing + if len(notified_files) > 0: + timeout = inotify_debounce + elif is_testing: + timeout = self.testing_timeout_ms + else: + timeout = None + if self.stop_flag.is_set(): logger.debug("Finishing because event is set") finished = True diff --git a/src/documents/tests/test_management_consumer.py b/src/documents/tests/test_management_consumer.py index 71cc97be1..be8f26d12 100644 --- a/src/documents/tests/test_management_consumer.py +++ b/src/documents/tests/test_management_consumer.py @@ -2,7 +2,6 @@ import filecmp import os import shutil from threading import Thread -from time import monotonic from time import sleep from unittest import mock