Separate log clearing from reading

This commit is contained in:
Kristóf Tóth 2018-05-28 15:02:53 +02:00
parent 44df95a434
commit 1a93dad562
2 changed files with 14 additions and 16 deletions

View File

@ -44,12 +44,15 @@ class ProcessManagingEventHandler(EventHandlerBase):
def handle_event(self, message): def handle_event(self, message):
try: try:
data = message['data'] data = message['data']
self.processmanager(data['command'], data['process_name']) try:
message['data']['log'] = self.processmanager.read_log_stdout(message['data']['process_name']) self.processmanager(data['command'], data['process_name'])
return message 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: except KeyError:
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) 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

View File

@ -27,16 +27,11 @@ class SupervisorMixin(SupervisorBaseMixin):
class SupervisorLogMixin(SupervisorBaseMixin): class SupervisorLogMixin(SupervisorBaseMixin):
def read_log_stdout(self, process_name): def read_stdout(self, process_name):
return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name) return self.supervisor.readProcessStdoutLog(process_name, 0, 0)
def read_log_stderr(self, process_name): def read_stderr(self, process_name):
return self._read_log_internal(self.supervisor.readProcessStderrLog, process_name) return self.supervisor.readProcessStderrLog(process_name, 0, 0)
def _read_log_internal(self, read_method, process_name):
log = read_method(process_name, 0, 0)
self.clear_logs(process_name)
return log
def clear_logs(self, process_name): def clear_logs(self, process_name):
for logfile in ('stdout_logfile', 'stderr_logfile'): for logfile in ('stdout_logfile', 'stderr_logfile'):