Rework ProcessManagingEH log API

This commit is contained in:
Kristóf Tóth 2018-05-28 16:36:59 +02:00
parent 1a93dad562
commit 9723f98950
2 changed files with 7 additions and 5 deletions

View File

@ -46,13 +46,12 @@ class ProcessManagingEventHandler(EventHandlerBase):
data = message['data'] data = message['data']
try: try:
self.processmanager(data['command'], data['process_name']) self.processmanager(data['command'], data['process_name'])
message['data']['log'] = self.processmanager.read_stdout(data['process_name'])
return message
except SupervisorFault as fault: except SupervisorFault as fault:
message['data']['error'] = fault.faultString message['data']['error'] = fault.faultString
message['data']['log'] = self.processmanager.read_stderr(data['process_name'])
return message
finally: finally:
message['data']['stdout'] = self.processmanager.read_stdout(data['process_name'])
message['data']['stderr'] = self.processmanager.read_stderr(data['process_name'])
self.processmanager.clear_logs(data['process_name']) self.processmanager.clear_logs(data['process_name'])
return message
except KeyError: except KeyError:
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)

View File

@ -35,5 +35,8 @@ class SupervisorLogMixin(SupervisorBaseMixin):
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'):
try:
remove(self.supervisor.getProcessInfo(process_name)[logfile]) remove(self.supervisor.getProcessInfo(process_name)[logfile])
except FileNotFoundError:
pass
self.supervisor.clearProcessLogs(process_name) self.supervisor.clearProcessLogs(process_name)