Browse Source

Modify watchdog related functionality

Specifically, make the code around watchdog accept a list of dirs
to watch, instead of a single one. That way, we can watch multiple
files.

Change-Id: If685428f7e7bbd251a61ac4fb57e3a2f63edecbb
Pranesh Pandurangan 4 years ago
parent
commit
a7479d66e8
2 changed files with 9 additions and 6 deletions
  1. 6
    4
      entropy/engine.py
  2. 3
    2
      entropy/utils.py

+ 6
- 4
entropy/engine.py View File

@@ -41,8 +41,8 @@ class Engine(object):
41 41
         Engine.set_logger(**cfg_data)
42 42
         # constants
43 43
         # TODO(praneshp): Hardcode for now, could/should be cmdline input
44
-        self._engine_cfg_data = cfg_data
45 44
         self.max_workers = 8
45
+        self._engine_cfg_data = cfg_data
46 46
         self.audit_type = 'audit'
47 47
         self.repair_type = 'repair'
48 48
         self.entropy_exchange = Exchange('entropy_exchange', type='fanout')
@@ -69,6 +69,7 @@ class Engine(object):
69 69
         # Private variables to keep track of repair scripts.
70 70
         self._repairs = []
71 71
         self._known_routing_keys = set()
72
+
72 73
         LOG.info('Created engine obj %s', self.name)
73 74
 
74 75
     # TODO(praneshp): Move to utils?
@@ -108,7 +109,7 @@ class Engine(object):
108 109
         self.futures.append(scheduler)
109 110
 
110 111
         # watchdog
111
-        watchdog_thread = self.start_watchdog(self.cfg_dir)
112
+        watchdog_thread = self.start_watchdog()
112 113
         watchdog_thread.join()
113 114
 
114 115
     def schedule(self):
@@ -195,9 +196,10 @@ class Engine(object):
195 196
         LOG.info('Repair configuration changed')
196 197
         self.futures.extend(self.start_react_scripts())
197 198
 
198
-    def start_watchdog(self, dir_to_watch):
199
+    def start_watchdog(self):
199 200
         LOG.debug('Watchdog mapping is: ', self._watchdog_event_fn)
200
-        return utils.watch_dir_for_change(dir_to_watch,
201
+        dirs_to_watch = [utils.get_filename_and_path(self.repair_cfg)[0]]
202
+        return utils.watch_dir_for_change(dirs_to_watch,
201 203
                                           self._watchdog_event_fn)
202 204
 
203 205
     def setup_audit(self, execution_time, audit_list):

+ 3
- 2
entropy/utils.py View File

@@ -103,10 +103,11 @@ class WatchdogHandler(FileSystemEventHandler):
103 103
             LOG.error('no associated function for %s', event.src_path)
104 104
 
105 105
 
106
-def watch_dir_for_change(dir_to_watch, event_fn):
106
+def watch_dir_for_change(dirs_to_watch, event_fn):
107 107
     event_handler = WatchdogHandler(event_fn)
108 108
     observer = Observer()
109
-    observer.schedule(event_handler, path=dir_to_watch)
109
+    for directory in dirs_to_watch:
110
+        observer.schedule(event_handler, path=directory)
110 111
     observer.start()
111 112
     return observer
112 113
 

Loading…
Cancel
Save