mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:11:32 +00:00
Merge pull request #19 from avatao-content/error_handling
Implement robust error handling
This commit is contained in:
commit
cb3d7b0e04
@ -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):
|
||||
try:
|
||||
data = data_json['data']
|
||||
self.processmanager(data['command'], data['process_name'])
|
||||
self.uplink.send(self.key, {'data': {'process_name': 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
|
||||
|
@ -84,10 +84,13 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
data['files'] = self.filemanager.files
|
||||
|
||||
def handle_event(self, key, 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()
|
||||
|
@ -23,8 +23,11 @@ class TerminadoEventHandler(TriggerlessEventHandler):
|
||||
|
||||
def handle_event(self, key, data_json):
|
||||
log.debug('TerminadoEventHandler received event: {}'.format(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'])
|
||||
|
Loading…
Reference in New Issue
Block a user