diff --git a/tfw/components/frontend/__init__.py b/tfw/components/frontend/__init__.py index 4ce9e31..2300690 100644 --- a/tfw/components/frontend/__init__.py +++ b/tfw/components/frontend/__init__.py @@ -1,2 +1,3 @@ from .frontend_proxy_handler import FrontendProxyHandler +from .console_logs_handler import ConsoleLogsHandler from .message_sender import MessageSender diff --git a/tfw/components/frontend/console_logs_handler.py b/tfw/components/frontend/console_logs_handler.py new file mode 100644 index 0000000..c3baf45 --- /dev/null +++ b/tfw/components/frontend/console_logs_handler.py @@ -0,0 +1,19 @@ +import logging + +LOG = logging.getLogger(__name__) + + +class ConsoleLogsHandler: + keys = ['process.log.new'] + + def __init__(self, *, stream): + self.stream = stream + + def handle_event(self, message, connector): + try: + connector.send_message({ + 'key': 'console.write', + 'value': message[self.stream] + }) + except KeyError: + LOG.error('Invalid %s message received: %s', self.keys, message) diff --git a/tfw/components/process_management/process_handler.py b/tfw/components/process_management/process_handler.py index 33e58fa..e24a83f 100644 --- a/tfw/components/process_management/process_handler.py +++ b/tfw/components/process_management/process_handler.py @@ -3,18 +3,16 @@ from xmlrpc.client import Fault as SupervisorFault from tfw.internals.networking import Scope -from .supervisor import ProcessManager, ProcessLogManager +from .supervisor import ProcessManager LOG = logging.getLogger(__name__) -class ProcessHandler(ProcessManager, ProcessLogManager): +class ProcessHandler(ProcessManager): keys = ['process'] - def __init__(self, *, supervisor_uri, log_tail=0): + def __init__(self, *, supervisor_uri): ProcessManager.__init__(self, supervisor_uri) - ProcessLogManager.__init__(self, supervisor_uri) - self.log_tail = log_tail self.commands = { 'process.start': self.start_process, @@ -28,15 +26,6 @@ class ProcessHandler(ProcessManager, ProcessLogManager): self.commands[message['key']](message['name']) except SupervisorFault as fault: message['error'] = fault.faultString - finally: - message['stdout'] = self.read_stdout( - message['name'], - self.log_tail - ) - message['stderr'] = self.read_stderr( - message['name'], - self.log_tail - ) connector.send_message(message, scope=Scope.WEBSOCKET) except KeyError: if not message['key'].startswith('process.log'):