mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 13:41:31 +00:00
Move initial FSM trigger to backend
This commit is contained in:
parent
c753b63273
commit
e0a915ac55
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user