mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:31:32 +00:00
Separate log clearing from reading
This commit is contained in:
parent
44df95a434
commit
1a93dad562
@ -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']
|
||||||
|
try:
|
||||||
self.processmanager(data['command'], data['process_name'])
|
self.processmanager(data['command'], data['process_name'])
|
||||||
message['data']['log'] = self.processmanager.read_log_stdout(message['data']['process_name'])
|
message['data']['log'] = self.processmanager.read_stdout(data['process_name'])
|
||||||
return message
|
return message
|
||||||
except KeyError:
|
|
||||||
LOG.error('IGNORING MESSAGE: Invalid message received: %s', 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_log_stderr(message['data']['process_name'])
|
message['data']['log'] = self.processmanager.read_stderr(data['process_name'])
|
||||||
return message
|
return message
|
||||||
|
finally:
|
||||||
|
self.processmanager.clear_logs(data['process_name'])
|
||||||
|
except KeyError:
|
||||||
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
||||||
|
@ -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'):
|
||||||
|
Loading…
Reference in New Issue
Block a user