From 552c9f5f93ea205c86b15a2c1c4f8d23b2ad35e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 15 Aug 2019 10:43:30 +0200 Subject: [PATCH 1/2] Rename FrontendHandler -> FrontendProxyHandler --- tfw/components/frontend/__init__.py | 2 +- .../frontend/{frontend_handler.py => frontend_proxy_handler.py} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename tfw/components/frontend/{frontend_handler.py => frontend_proxy_handler.py} (96%) diff --git a/tfw/components/frontend/__init__.py b/tfw/components/frontend/__init__.py index 3e0b871..4ce9e31 100644 --- a/tfw/components/frontend/__init__.py +++ b/tfw/components/frontend/__init__.py @@ -1,2 +1,2 @@ -from .frontend_handler import FrontendHandler +from .frontend_proxy_handler import FrontendProxyHandler from .message_sender import MessageSender diff --git a/tfw/components/frontend/frontend_handler.py b/tfw/components/frontend/frontend_proxy_handler.py similarity index 96% rename from tfw/components/frontend/frontend_handler.py rename to tfw/components/frontend/frontend_proxy_handler.py index dfb50bf..10d1080 100644 --- a/tfw/components/frontend/frontend_handler.py +++ b/tfw/components/frontend/frontend_proxy_handler.py @@ -3,7 +3,7 @@ from tfw.internals.networking import Scope from .message_storage import FrontendMessageStorage -class FrontendHandler: +class FrontendProxyHandler: keys = ['console', 'dashboard', 'message', 'ide.read', 'recover'] def __init__(self): From c84ac9914164673ce750613cd51b5bd7cf402354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 15 Aug 2019 14:37:08 +0200 Subject: [PATCH 2/2] Write process logs to console with a separate handler --- tfw/components/frontend/__init__.py | 1 + .../frontend/console_logs_handler.py | 19 +++++++++++++++++++ .../process_management/process_handler.py | 17 +++-------------- 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 tfw/components/frontend/console_logs_handler.py 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'):