baseimage-tutorial-framework/tfw/components/process_management/process_handler.py

33 lines
1.0 KiB
Python
Raw Normal View History

2019-06-10 13:32:45 +00:00
import logging
from xmlrpc.client import Fault as SupervisorFault
from tfw.internals.networking import Scope, Intent
from .supervisor import ProcessManager
LOG = logging.getLogger(__name__)
2018-02-16 11:07:16 +00:00
class ProcessHandler(ProcessManager):
2019-08-08 13:05:37 +00:00
keys = ['process']
def __init__(self, *, supervisor_uri):
2019-07-23 13:32:50 +00:00
ProcessManager.__init__(self, supervisor_uri)
self.commands = {
'process.start': self.start_process,
'process.stop': self.stop_process,
'process.restart': self.restart_process
}
2018-02-16 11:07:16 +00:00
def handle_event(self, message, connector):
try:
2018-05-28 13:02:53 +00:00
try:
self.commands[message['key']](message['name'])
2018-05-28 13:02:53 +00:00
except SupervisorFault as fault:
message['error'] = fault.faultString
connector.send_message(message, scope=Scope.BROADCAST, intent=Intent.EVENT)
except KeyError:
2019-08-08 13:05:37 +00:00
if not message['key'].startswith('process.log'):
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)