2019-06-10 13:32:45 +00:00
|
|
|
import logging
|
2018-03-07 14:14:33 +00:00
|
|
|
from xmlrpc.client import Fault as SupervisorFault
|
2018-03-02 09:21:56 +00:00
|
|
|
|
2019-07-24 13:17:16 +00:00
|
|
|
from tfw.internals.networking import Scope
|
|
|
|
|
2019-08-15 12:37:08 +00:00
|
|
|
from .supervisor import ProcessManager
|
2018-03-25 14:06:59 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
2018-02-16 11:07:16 +00:00
|
|
|
|
|
|
|
|
2019-08-15 12:37:08 +00:00
|
|
|
class ProcessHandler(ProcessManager):
|
2019-08-08 13:05:37 +00:00
|
|
|
keys = ['process']
|
|
|
|
|
2019-08-15 12:37:08 +00:00
|
|
|
def __init__(self, *, supervisor_uri):
|
2019-07-23 13:32:50 +00:00
|
|
|
ProcessManager.__init__(self, supervisor_uri)
|
2019-08-07 07:47:57 +00:00
|
|
|
|
2019-07-05 13:25:59 +00:00
|
|
|
self.commands = {
|
2019-08-07 07:47:57 +00:00
|
|
|
'process.start': self.start_process,
|
|
|
|
'process.stop': self.stop_process,
|
|
|
|
'process.restart': self.restart_process
|
2019-07-05 13:25:59 +00:00
|
|
|
}
|
2018-02-16 11:07:16 +00:00
|
|
|
|
2019-07-30 13:17:29 +00:00
|
|
|
def handle_event(self, message, connector):
|
2018-03-07 13:45:43 +00:00
|
|
|
try:
|
2018-05-28 13:02:53 +00:00
|
|
|
try:
|
2019-08-07 07:47:57 +00:00
|
|
|
self.commands[message['key']](message['name'])
|
2018-05-28 13:02:53 +00:00
|
|
|
except SupervisorFault as fault:
|
2019-08-07 07:47:57 +00:00
|
|
|
message['error'] = fault.faultString
|
2019-07-30 13:17:29 +00:00
|
|
|
connector.send_message(message, scope=Scope.WEBSOCKET)
|
2018-03-07 13:45:43 +00:00
|
|
|
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)
|