From c5afdfb1b2abad3bd98515e61ff3b663c285a115 Mon Sep 17 00:00:00 2001 From: "R. Richard" Date: Fri, 23 Aug 2019 16:24:47 +0200 Subject: [PATCH] Create handler for deploying in the IDE --- .../frontend/frontend_proxy_handler.py | 2 +- tfw/components/ide/__init__.py | 1 + tfw/components/ide/deploy_handler.py | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tfw/components/ide/deploy_handler.py diff --git a/tfw/components/frontend/frontend_proxy_handler.py b/tfw/components/frontend/frontend_proxy_handler.py index e7c7b06..e0a3dc1 100644 --- a/tfw/components/frontend/frontend_proxy_handler.py +++ b/tfw/components/frontend/frontend_proxy_handler.py @@ -4,7 +4,7 @@ from .message_storage import FrontendMessageStorage class FrontendProxyHandler: - keys = ['console', 'dashboard', 'frontend.ready', 'message', 'ide.read'] + keys = ['console', 'dashboard', 'frontend.ready', 'message', 'ide.read', 'deploy.finish'] def __init__(self): self.connector = None diff --git a/tfw/components/ide/__init__.py b/tfw/components/ide/__init__.py index 2d4ae3e..81b35cf 100644 --- a/tfw/components/ide/__init__.py +++ b/tfw/components/ide/__init__.py @@ -1 +1,2 @@ from .ide_handler import IdeHandler +from .deploy_handler import DeployHandler diff --git a/tfw/components/ide/deploy_handler.py b/tfw/components/ide/deploy_handler.py new file mode 100644 index 0000000..ed9886e --- /dev/null +++ b/tfw/components/ide/deploy_handler.py @@ -0,0 +1,29 @@ +class DeployHandler: + keys = ['deploy.start', 'process.restart'] + + def __init__(self, process_name='webservice'): + self.process_name = process_name + + self.commands = { + 'deploy.start': self.handle_deploy, + 'process.restart': self.handle_process + } + + def handle_event(self, message, _): + try: + self.commands[message['key']](message) + except KeyError: + LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) + + def handle_deploy(self, message): + self.connector.send_message({ + 'key': 'process.restart', + 'name': self.process_name + }) + + def handle_process(self, message): + self.connector.send_message({ + 'key': 'deploy.finish', + 'status': 'success' if 'error' not in message else 'error' + }) +