mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 02:21:32 +00:00
Refactor ProcessManagingEventHandler
This commit is contained in:
parent
a50a173f54
commit
8d8b60d143
@ -2,14 +2,21 @@ from tfw.event_handler_base import EventHandlerBase
|
|||||||
from tfw.components.mixins import SupervisorMixin
|
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):
|
class ProcessManagingEventHandler(EventHandlerBase, SupervisorMixin):
|
||||||
def __init__(self, anchor, supervisor_process_name):
|
def __init__(self, anchor, supervisor_process_name):
|
||||||
super().__init__(anchor)
|
super().__init__(anchor)
|
||||||
self.process = supervisor_process_name
|
self.processmanager = ProcessManager(supervisor_process_name)
|
||||||
self.commands = {'start': self.start_process,
|
|
||||||
'stop': self.stop_process,
|
|
||||||
'restart': self.restart_process}
|
|
||||||
|
|
||||||
def handle_event(self, anchor, data_json):
|
def handle_event(self, anchor, data_json):
|
||||||
data = data_json['data']
|
self.processmanager(data_json['data']['command'])
|
||||||
self.commands[data['command']]()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user