From e0a915ac556c4dd3f4fbf67907906d32a5d17f3d Mon Sep 17 00:00:00 2001 From: "R. Richard" Date: Thu, 15 Aug 2019 15:36:57 +0200 Subject: [PATCH] Move initial FSM trigger to backend --- tfw/components/frontend/frontend_proxy_handler.py | 4 ++-- tfw/components/fsm/fsm_handler.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tfw/components/frontend/frontend_proxy_handler.py b/tfw/components/frontend/frontend_proxy_handler.py index 10d1080..a46f015 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', 'message', 'ide.read', 'recover'] + keys = ['console', 'dashboard', 'frontend.ready', 'message', 'ide.read'] def __init__(self): self.connector = None @@ -15,7 +15,7 @@ class FrontendProxyHandler: def handle_event(self, message, _): self._frontend_message_storage.save_message(message) - if message['key'] == 'recover': + if message['key'] == 'frontend.ready': self.recover_frontend() if self._filter_message(message): self.send_message(message) diff --git a/tfw/components/fsm/fsm_handler.py b/tfw/components/fsm/fsm_handler.py index 24b8231..b26db86 100644 --- a/tfw/components/fsm/fsm_handler.py +++ b/tfw/components/fsm/fsm_handler.py @@ -11,16 +11,21 @@ LOG = logging.getLogger(__name__) class FSMHandler: keys = ['fsm'] - def __init__(self, *, fsm_type): + def __init__(self, *, fsm_type, initial_trigger): self.fsm = fsm_type() self._fsm_updater = FSMUpdater(self.fsm) self.auth_key = KeyManager().auth_key + self.initial_trigger = initial_trigger self.command_handlers = { + 'frontend.ready': self.handle_ready, 'fsm.step' : self.handle_step, 'fsm.announce' : self.handle_announce } + def start(self): + self.connector.subscribe('frontend.ready') + def handle_event(self, message, connector): try: message = self.command_handlers[message['key']](message) @@ -31,6 +36,11 @@ class FSMHandler: except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) + def handle_ready(self, message): + self.fsm.step(self.initial_trigger) + self.connector.unsubscribe('frontend.ready') + return message + def handle_step(self, message): if self.fsm.step(message['trigger']): return message