diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 8fd1bea..7b387a5 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -2,14 +2,21 @@ from tfw.event_handler_base import EventHandlerBase from tfw.components.mixins import SupervisorMixin +class ProcessManager(SupervisorMixin): + def __init__(self, process_name): + self.process = process_name + self.commands = {'start': self.start_process, + 'stop': self.stop_process, + 'restart': self.restart_process} + + def __call__(self, command): + self.commands[command]() + + class ProcessManagingEventHandler(EventHandlerBase, SupervisorMixin): def __init__(self, anchor, supervisor_process_name): super().__init__(anchor) - self.process = supervisor_process_name - self.commands = {'start': self.start_process, - 'stop': self.stop_process, - 'restart': self.restart_process} + self.processmanager = ProcessManager(supervisor_process_name) def handle_event(self, anchor, data_json): - data = data_json['data'] - self.commands[data['command']]() + self.processmanager(data_json['data']['command'])