Skip to content

Commit f82d837

Browse files
committed
Automation helper: Set inotify buffer delay to 0
In the composition tests, we are observing events arriving too late according to the automation helper log. This change might solve the issue. CMK-21699 Change-Id: Ieb48770101972a3deffd0d1c41554de92b310253
1 parent a6a55a4 commit f82d837

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmk/base/automation_helper/_watcher.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,28 @@
88
from collections.abc import Generator, Sequence
99

1010
from watchdog.events import FileSystemEvent, PatternMatchingEventHandler
11-
from watchdog.observers import Observer
11+
from watchdog.observers.inotify import InotifyObserver
12+
from watchdog.observers.inotify_buffer import InotifyBuffer
1213

1314
from ._cache import Cache, CacheError
1415
from ._config import WatcherConfig
1516
from ._log import LOGGER
1617

18+
# When a file or folder is moved, two events are created: IN_MOVED_FROM and IN_MOVED_TO.
19+
# watchdog tries to combine these two events into a single move event. In case it received
20+
# IN_MOVED_FROM but not yet in IN_MOVED_TO, it waits up `InotifyBuffer.delay` seconds for
21+
# IN_MOVED_TO, thereby delaying the reporting of other events. This might be an actual problem
22+
# for us if an automation call is triggered right after files relevant to this call were modified.
23+
# In such scenarios, the reload notification from the watcher might arrive too late if watchdog
24+
# adds some delay. As a result, the automation call uses an outdated configuration.
25+
# See also https://man7.org/linux/man-pages/man7/inotify.7.html, "Dealing with rename() events"
26+
InotifyBuffer.delay = 0.0
27+
1728

1829
@contextlib.contextmanager
1930
def run(config: WatcherConfig, cache: Cache) -> Generator[None]:
2031
LOGGER.info("[watcher] Initializing")
21-
observer = Observer()
32+
observer = InotifyObserver(generate_full_events=True)
2233
for schedule in config.schedules:
2334
handler = _AutomationWatcherHandler(
2435
cache=cache,

0 commit comments

Comments
 (0)