From f874deff6ef32d8eb0e1d367da10c03b34aa00e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 8 Mar 2018 16:04:35 +0100 Subject: [PATCH] Implement stderr feedback on deployment failure (ProcessManagingEventHandler) --- lib/tfw/components/mixins/supervisor_mixin.py | 3 +++ lib/tfw/components/process_managing_event_handler.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tfw/components/mixins/supervisor_mixin.py b/lib/tfw/components/mixins/supervisor_mixin.py index ab483ff..7023105 100644 --- a/lib/tfw/components/mixins/supervisor_mixin.py +++ b/lib/tfw/components/mixins/supervisor_mixin.py @@ -15,6 +15,9 @@ class SupervisorMixin: def start_process(self, process_name): self.supervisor.startProcess(process_name) + def read_log(self, process_name): + return self.supervisor.readProcessStderrLog(process_name, 0, 0) + def restart_process(self, process_name): self.stop_process(process_name) self.start_process(process_name) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 938c5aa..45e2cdb 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -11,10 +11,11 @@ class ProcessManager(SupervisorMixin): def __init__(self): self.commands = {'start': self.start_process, 'stop': self.stop_process, - 'restart': self.restart_process} + 'restart': self.restart_process, + 'readlog': self.read_log} def __call__(self, command, process_name): - self.commands[command](process_name) + return self.commands[command](process_name) class ProcessManagingEventHandler(TriggerlessEventHandler): @@ -43,5 +44,6 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) except SupervisorFault as fault: data_json['data']['error'] = fault.faultString + data_json['data']['log'] = self.processmanager.read_log(data_json['data']['process_name']) log.debug('Failed to execute command on process: {}'.format(data_json)) return data_json