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
This commit is contained in:
parent
8967185608
commit
a7479d66e8
|
@ -41,8 +41,8 @@ class Engine(object):
|
||||||
Engine.set_logger(**cfg_data)
|
Engine.set_logger(**cfg_data)
|
||||||
# constants
|
# constants
|
||||||
# TODO(praneshp): Hardcode for now, could/should be cmdline input
|
# TODO(praneshp): Hardcode for now, could/should be cmdline input
|
||||||
self._engine_cfg_data = cfg_data
|
|
||||||
self.max_workers = 8
|
self.max_workers = 8
|
||||||
|
self._engine_cfg_data = cfg_data
|
||||||
self.audit_type = 'audit'
|
self.audit_type = 'audit'
|
||||||
self.repair_type = 'repair'
|
self.repair_type = 'repair'
|
||||||
self.entropy_exchange = Exchange('entropy_exchange', type='fanout')
|
self.entropy_exchange = Exchange('entropy_exchange', type='fanout')
|
||||||
|
@ -69,6 +69,7 @@ class Engine(object):
|
||||||
# Private variables to keep track of repair scripts.
|
# Private variables to keep track of repair scripts.
|
||||||
self._repairs = []
|
self._repairs = []
|
||||||
self._known_routing_keys = set()
|
self._known_routing_keys = set()
|
||||||
|
|
||||||
LOG.info('Created engine obj %s', self.name)
|
LOG.info('Created engine obj %s', self.name)
|
||||||
|
|
||||||
# TODO(praneshp): Move to utils?
|
# TODO(praneshp): Move to utils?
|
||||||
|
@ -108,7 +109,7 @@ class Engine(object):
|
||||||
self.futures.append(scheduler)
|
self.futures.append(scheduler)
|
||||||
|
|
||||||
# watchdog
|
# watchdog
|
||||||
watchdog_thread = self.start_watchdog(self.cfg_dir)
|
watchdog_thread = self.start_watchdog()
|
||||||
watchdog_thread.join()
|
watchdog_thread.join()
|
||||||
|
|
||||||
def schedule(self):
|
def schedule(self):
|
||||||
|
@ -195,9 +196,10 @@ class Engine(object):
|
||||||
LOG.info('Repair configuration changed')
|
LOG.info('Repair configuration changed')
|
||||||
self.futures.extend(self.start_react_scripts())
|
self.futures.extend(self.start_react_scripts())
|
||||||
|
|
||||||
def start_watchdog(self, dir_to_watch):
|
def start_watchdog(self):
|
||||||
LOG.debug('Watchdog mapping is: ', self._watchdog_event_fn)
|
LOG.debug('Watchdog mapping is: ', self._watchdog_event_fn)
|
||||||
return utils.watch_dir_for_change(dir_to_watch,
|
dirs_to_watch = [utils.get_filename_and_path(self.repair_cfg)[0]]
|
||||||
|
return utils.watch_dir_for_change(dirs_to_watch,
|
||||||
self._watchdog_event_fn)
|
self._watchdog_event_fn)
|
||||||
|
|
||||||
def setup_audit(self, execution_time, audit_list):
|
def setup_audit(self, execution_time, audit_list):
|
||||||
|
|
|
@ -103,10 +103,11 @@ class WatchdogHandler(FileSystemEventHandler):
|
||||||
LOG.error('no associated function for %s', event.src_path)
|
LOG.error('no associated function for %s', event.src_path)
|
||||||
|
|
||||||
|
|
||||||
def watch_dir_for_change(dir_to_watch, event_fn):
|
def watch_dir_for_change(dirs_to_watch, event_fn):
|
||||||
event_handler = WatchdogHandler(event_fn)
|
event_handler = WatchdogHandler(event_fn)
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(event_handler, path=dir_to_watch)
|
for directory in dirs_to_watch:
|
||||||
|
observer.schedule(event_handler, path=directory)
|
||||||
observer.start()
|
observer.start()
|
||||||
return observer
|
return observer
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue