mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:11:32 +00:00
Trigger first step in an individual event handler
This commit is contained in:
parent
1f813a2138
commit
ddb47d696c
@ -1,4 +1,5 @@
|
|||||||
from .console_logs_handler import ConsoleLogsHandler
|
from .console_logs_handler import ConsoleLogsHandler
|
||||||
from .frontend_proxy_handler import FrontendProxyHandler
|
from .frontend_proxy_handler import FrontendProxyHandler
|
||||||
|
from .frontend_ready_handler import FrontendReadyHandler
|
||||||
from .message_queue_handler import MessageQueueHandler
|
from .message_queue_handler import MessageQueueHandler
|
||||||
from .message_sender import MessageSender
|
from .message_sender import MessageSender
|
||||||
|
39
tfw/components/frontend/frontend_ready_handler.py
Normal file
39
tfw/components/frontend/frontend_ready_handler.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from tfw.internals.crypto import KeyManager, sign_message
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class FrontendReadyHandler:
|
||||||
|
keys = ['frontend.ready', 'fsm.update']
|
||||||
|
|
||||||
|
def __init__(self, initial_trigger):
|
||||||
|
self.connector = None
|
||||||
|
self._auth_key = KeyManager().auth_key
|
||||||
|
self.initial_trigger = initial_trigger
|
||||||
|
|
||||||
|
self.commands = {
|
||||||
|
'frontend.ready': self.handle_ready,
|
||||||
|
'fsm.update': self.handle_update
|
||||||
|
}
|
||||||
|
|
||||||
|
def handle_event(self, message, _):
|
||||||
|
try:
|
||||||
|
self.commands[message['key']]()
|
||||||
|
except KeyError:
|
||||||
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
||||||
|
|
||||||
|
def handle_ready(self):
|
||||||
|
trigger = {
|
||||||
|
'key': 'fsm.step',
|
||||||
|
'trigger': self.initial_trigger
|
||||||
|
}
|
||||||
|
sign_message(self._auth_key, trigger)
|
||||||
|
self.connector.send_message(trigger)
|
||||||
|
|
||||||
|
def handle_update(self):
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
pass
|
@ -11,22 +11,17 @@ LOG = logging.getLogger(__name__)
|
|||||||
class FSMHandler:
|
class FSMHandler:
|
||||||
keys = ['fsm']
|
keys = ['fsm']
|
||||||
|
|
||||||
def __init__(self, *, fsm_type, initial_trigger):
|
def __init__(self, *, fsm_type):
|
||||||
self.connector = None
|
self.connector = None
|
||||||
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.update' : self.handle_update
|
'fsm.update' : self.handle_update
|
||||||
}
|
}
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.connector.subscribe('frontend.ready')
|
|
||||||
|
|
||||||
def handle_event(self, message, _):
|
def handle_event(self, message, _):
|
||||||
try:
|
try:
|
||||||
message = self.command_handlers[message['key']](message)
|
message = self.command_handlers[message['key']](message)
|
||||||
@ -37,11 +32,6 @@ 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): # pylint: disable=inconsistent-return-statements
|
def handle_step(self, message): # pylint: disable=inconsistent-return-statements
|
||||||
if self.fsm.step(message['trigger']):
|
if self.fsm.step(message['trigger']):
|
||||||
return message
|
return message
|
||||||
|
Loading…
Reference in New Issue
Block a user