diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 1873dcf..0685b48 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -44,12 +44,15 @@ class ProcessManagingEventHandler(EventHandlerBase): def handle_event(self, message): try: data = message['data'] - self.processmanager(data['command'], data['process_name']) - message['data']['log'] = self.processmanager.read_log_stdout(message['data']['process_name']) - return message + try: + self.processmanager(data['command'], data['process_name']) + message['data']['log'] = self.processmanager.read_stdout(data['process_name']) + return message + except SupervisorFault as fault: + message['data']['error'] = fault.faultString + message['data']['log'] = self.processmanager.read_stderr(data['process_name']) + return message + finally: + self.processmanager.clear_logs(data['process_name']) except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) - except SupervisorFault as fault: - message['data']['error'] = fault.faultString - message['data']['log'] = self.processmanager.read_log_stderr(message['data']['process_name']) - return message diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index 3df6b48..4586e85 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -27,16 +27,11 @@ class SupervisorMixin(SupervisorBaseMixin): class SupervisorLogMixin(SupervisorBaseMixin): - def read_log_stdout(self, process_name): - return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name) + def read_stdout(self, process_name): + return self.supervisor.readProcessStdoutLog(process_name, 0, 0) - def read_log_stderr(self, process_name): - return self._read_log_internal(self.supervisor.readProcessStderrLog, process_name) - - def _read_log_internal(self, read_method, process_name): - log = read_method(process_name, 0, 0) - self.clear_logs(process_name) - return log + def read_stderr(self, process_name): + return self.supervisor.readProcessStderrLog(process_name, 0, 0) def clear_logs(self, process_name): for logfile in ('stdout_logfile', 'stderr_logfile'):