mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 04:11:56 +00:00
Implement error handling on EventHandler exposing APIs
This commit is contained in:
parent
be6f657de1
commit
2c816d5a38
@ -36,6 +36,9 @@ 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'])
|
||||
self.uplink.send(self.key, {'data': {'process_name': data['process_name']}})
|
||||
except KeyError:
|
||||
log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json))
|
||||
|
@ -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()
|
||||
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user