Add engine_cfg to watchdog

Watch changes to engine config via watchdog. When the file is
modified, watchdog picks it up, verifies if the current engine
is disabled, and if yes, take steps in stop_engine(), to stop
the engine. That function is currently empty, will be filled in
in future commits

Change-Id: If3e2e952009f2f8a610459645c4403c77581e717
This commit is contained in:
Pranesh Pandurangan 2014-06-12 17:49:49 -07:00
parent a7479d66e8
commit b41ea8a81f
1 changed files with 15 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import datetime
import logging
import operator
import os
import tempfile
from concurrent import futures as cf
import croniter
@ -40,6 +41,8 @@ class Engine(object):
utils.reset_logger(logging.getLogger())
Engine.set_logger(**cfg_data)
# constants
# Well known file where all engines are stored.
self.engine_cfg = os.path.join(tempfile.gettempdir(), 'engines.cfg')
# TODO(praneshp): Hardcode for now, could/should be cmdline input
self.max_workers = 8
self._engine_cfg_data = cfg_data
@ -65,7 +68,8 @@ class Engine(object):
self.futures = []
self.run_queue = collections.deque()
# Private variables
self._watchdog_event_fn = {self.repair_cfg: self.repair_modified}
self._watchdog_event_fn = {self.repair_cfg: self.repair_modified,
self.engine_cfg: self.engine_disabled}
# Private variables to keep track of repair scripts.
self._repairs = []
self._known_routing_keys = set()
@ -192,13 +196,22 @@ class Engine(object):
LOG.exception("Could not run serializer for %s at %s",
self.name, current_time)
def engine_disabled(self):
engine_config = dict(utils.load_yaml(self.engine_cfg))[self.name]
if not engine_config['enabled']:
self.stop_engine()
def stop_engine(self):
pass
def repair_modified(self):
LOG.info('Repair configuration changed')
self.futures.extend(self.start_react_scripts())
def start_watchdog(self):
LOG.debug('Watchdog mapping is: ', self._watchdog_event_fn)
dirs_to_watch = [utils.get_filename_and_path(self.repair_cfg)[0]]
dirs_to_watch = [utils.get_filename_and_path(x)[0] for x in
self.engine_cfg, self.repair_cfg]
return utils.watch_dir_for_change(dirs_to_watch,
self._watchdog_event_fn)