mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 22:21:32 +00:00
Append deployment logs to every response of ProcessManagingEventHandler
This commit is contained in:
parent
293d7972f1
commit
bfd1efa9f9
@ -16,7 +16,8 @@ class ProcessManager(SupervisorMixin):
|
|||||||
self.commands = {'start': self.start_process,
|
self.commands = {'start': self.start_process,
|
||||||
'stop': self.stop_process,
|
'stop': self.stop_process,
|
||||||
'restart': self.restart_process,
|
'restart': self.restart_process,
|
||||||
'readlog': self.read_log}
|
'readlog': self.read_log_stdout,
|
||||||
|
'readerrlog': self.read_log_stderr}
|
||||||
|
|
||||||
def __call__(self, command, process_name):
|
def __call__(self, command, process_name):
|
||||||
return self.commands[command](process_name)
|
return self.commands[command](process_name)
|
||||||
@ -46,10 +47,11 @@ class ProcessManagingEventHandler(EventHandlerBase):
|
|||||||
try:
|
try:
|
||||||
data = message['data']
|
data = message['data']
|
||||||
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'])
|
||||||
return message
|
return message
|
||||||
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:
|
except SupervisorFault as fault:
|
||||||
message['data']['error'] = fault.faultString
|
message['data']['error'] = fault.faultString
|
||||||
message['data']['log'] = self.processmanager.read_log(message['data']['process_name'])
|
message['data']['log'] = self.processmanager.read_log_stderr(message['data']['process_name'])
|
||||||
return message
|
return message
|
||||||
|
@ -19,11 +19,21 @@ class SupervisorMixin:
|
|||||||
def start_process(self, process_name):
|
def start_process(self, process_name):
|
||||||
self.supervisor.startProcess(process_name)
|
self.supervisor.startProcess(process_name)
|
||||||
|
|
||||||
def read_log(self, process_name):
|
def read_log_stdout(self, process_name):
|
||||||
logs = self.supervisor.readProcessStderrLog(process_name, 0, 0)
|
return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name)
|
||||||
remove(self.supervisor.getProcessInfo(process_name)['stderr_logfile'])
|
|
||||||
|
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 clear_logs(self, process_name):
|
||||||
|
for logfile in ('stdout_logfile', 'stderr_logfile'):
|
||||||
|
remove(self.supervisor.getProcessInfo(process_name)[logfile])
|
||||||
self.supervisor.clearProcessLogs(process_name)
|
self.supervisor.clearProcessLogs(process_name)
|
||||||
return logs
|
|
||||||
|
|
||||||
def restart_process(self, process_name):
|
def restart_process(self, process_name):
|
||||||
self.stop_process(process_name)
|
self.stop_process(process_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user