baseimage-tutorial-framework/lib/tfw/components/process_managing_event_handler.py

23 lines
796 B
Python
Raw Normal View History

2018-02-16 11:07:16 +00:00
from tfw.event_handler_base import EventHandlerBase
from tfw.components.mixins import SupervisorMixin
2018-02-20 13:45:16 +00:00
class ProcessManager(SupervisorMixin):
def __init__(self, supervisor_process_name):
self.process_name = supervisor_process_name
2018-02-20 13:45:16 +00:00
self.commands = {'start': self.start_process,
'stop': self.stop_process,
'restart': self.restart_process}
def __call__(self, command):
self.commands[command]()
class ProcessManagingEventHandler(EventHandlerBase):
2018-02-16 11:07:16 +00:00
def __init__(self, anchor, supervisor_process_name):
super().__init__(anchor)
2018-02-20 13:45:16 +00:00
self.processmanager = ProcessManager(supervisor_process_name)
2018-02-16 11:07:16 +00:00
def handle_event(self, anchor, data_json):
2018-02-20 13:45:16 +00:00
self.processmanager(data_json['data']['command'])