diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 6fcc248..938c5aa 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -1,8 +1,8 @@ from functools import wraps +from xmlrpc.client import Fault as SupervisorFault from tfw.event_handler_base import TriggerlessEventHandler from tfw.components.mixins import SupervisorMixin -from tfw.networking.event_handlers.server_connector import ServerUplinkConnector from tfw.config.logs import logging log = logging.getLogger(__name__) @@ -23,7 +23,6 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): self.key = key self.monitor = dirmonitor self.processmanager = ProcessManager() - self.uplink = ServerUplinkConnector() def _with_monitor_paused(fun): @wraps(fun) @@ -36,6 +35,13 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): @_with_monitor_paused def handle_event(self, key, data_json): - data = data_json['data'] - self.processmanager(data['command'], data['process_name']) - self.uplink.send(self.key, {'data': {'process_name': data['process_name']}}) + try: + data = data_json['data'] + self.processmanager(data['command'], data['process_name']) + return data_json + except KeyError: + log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) + except SupervisorFault as fault: + data_json['data']['error'] = fault.faultString + log.debug('Failed to execute command on process: {}'.format(data_json)) + return data_json diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index dd26072..003264a 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -84,10 +84,13 @@ class SourceCodeEventHandler(TriggerlessEventHandler): data['files'] = self.filemanager.files def handle_event(self, key, data_json): - data = data_json['data'] - data_json['data'] = self.commands[data['command']](data) - self.attach_fileinfo(data) - return data_json + try: + data = data_json['data'] + data_json['data'] = self.commands[data['command']](data) + self.attach_fileinfo(data) + return data_json + except KeyError: + log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) def cleanup(self): self.monitor.stop() diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index 4a8f98a..649f823 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -23,8 +23,11 @@ class TerminadoEventHandler(TriggerlessEventHandler): def handle_event(self, key, data_json): log.debug('TerminadoEventHandler received event: {}'.format(data_json)) - data_json['data'] = self.commands[data_json['data']['command']](data_json['data']) - return data_json + try: + data_json['data'] = self.commands[data_json['data']['command']](data_json['data']) + return data_json + except KeyError: + log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) def write(self, data): self.terminado_server.pty.write(data['shellcmd'])