Merge pull request #19 from avatao-content/error_handling

Implement robust error handling
This commit is contained in:
Bokros Bálint 2018-03-07 17:07:42 +01:00 committed by GitHub
commit cb3d7b0e04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 11 deletions

View File

@ -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

View File

@ -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()

View File

@ -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'])