mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:01:31 +00:00
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
import logging
|
|
from xmlrpc.client import Fault as SupervisorFault
|
|
|
|
from tfw.internals.networking import Scope, Intent
|
|
|
|
from .supervisor import ProcessManager
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class ProcessHandler(ProcessManager):
|
|
keys = ['process']
|
|
type_id = 'ControlEventHandler'
|
|
|
|
def __init__(self, *, supervisor_uri):
|
|
ProcessManager.__init__(self, supervisor_uri)
|
|
|
|
self.commands = {
|
|
'process.start': self.start_process,
|
|
'process.stop': self.stop_process,
|
|
'process.restart': self.restart_process
|
|
}
|
|
|
|
def handle_event(self, message, connector):
|
|
try:
|
|
try:
|
|
self.commands[message['key']](message['name'])
|
|
except SupervisorFault as fault:
|
|
message['error'] = fault.faultString
|
|
connector.send_message(message, scope=Scope.BROADCAST, intent=Intent.EVENT)
|
|
except KeyError:
|
|
if not message['key'].startswith('process.log'):
|
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|