Move initial FSM trigger to backend

This commit is contained in:
R. Richard 2019-08-15 15:36:57 +02:00
parent c753b63273
commit e0a915ac55
2 changed files with 13 additions and 3 deletions

View File

@ -4,7 +4,7 @@ from .message_storage import FrontendMessageStorage
class FrontendProxyHandler: class FrontendProxyHandler:
keys = ['console', 'dashboard', 'message', 'ide.read', 'recover'] keys = ['console', 'dashboard', 'frontend.ready', 'message', 'ide.read']
def __init__(self): def __init__(self):
self.connector = None self.connector = None
@ -15,7 +15,7 @@ class FrontendProxyHandler:
def handle_event(self, message, _): def handle_event(self, message, _):
self._frontend_message_storage.save_message(message) self._frontend_message_storage.save_message(message)
if message['key'] == 'recover': if message['key'] == 'frontend.ready':
self.recover_frontend() self.recover_frontend()
if self._filter_message(message): if self._filter_message(message):
self.send_message(message) self.send_message(message)

View File

@ -11,16 +11,21 @@ LOG = logging.getLogger(__name__)
class FSMHandler: class FSMHandler:
keys = ['fsm'] keys = ['fsm']
def __init__(self, *, fsm_type): def __init__(self, *, fsm_type, initial_trigger):
self.fsm = fsm_type() self.fsm = fsm_type()
self._fsm_updater = FSMUpdater(self.fsm) self._fsm_updater = FSMUpdater(self.fsm)
self.auth_key = KeyManager().auth_key self.auth_key = KeyManager().auth_key
self.initial_trigger = initial_trigger
self.command_handlers = { self.command_handlers = {
'frontend.ready': self.handle_ready,
'fsm.step' : self.handle_step, 'fsm.step' : self.handle_step,
'fsm.announce' : self.handle_announce 'fsm.announce' : self.handle_announce
} }
def start(self):
self.connector.subscribe('frontend.ready')
def handle_event(self, message, connector): def handle_event(self, message, connector):
try: try:
message = self.command_handlers[message['key']](message) message = self.command_handlers[message['key']](message)
@ -31,6 +36,11 @@ class FSMHandler:
except KeyError: except KeyError:
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) 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): def handle_step(self, message):
if self.fsm.step(message['trigger']): if self.fsm.step(message['trigger']):
return message return message