mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-22 16:11:56 +00:00
Refactor API message format
This commit is contained in:
parent
996e8e2af7
commit
25f54a71b5
@ -13,7 +13,7 @@ class ConsoleLogsHandler:
|
||||
try:
|
||||
connector.send_message({
|
||||
'key': 'console.write',
|
||||
'value': message[self.stream]
|
||||
'content': message[self.stream]
|
||||
})
|
||||
except KeyError:
|
||||
LOG.error('Invalid %s message received: %s', self.keys, message)
|
||||
|
@ -26,8 +26,8 @@ class FrontendReadyHandler:
|
||||
|
||||
def handle_ready(self):
|
||||
trigger = {
|
||||
'key': 'fsm.step',
|
||||
'trigger': self.initial_trigger
|
||||
'key': 'fsm.trigger',
|
||||
'transition': self.initial_trigger
|
||||
}
|
||||
sign_message(self._auth_key, trigger)
|
||||
self.connector.send_message(trigger)
|
||||
|
@ -25,8 +25,8 @@ class MessageQueueHandler:
|
||||
|
||||
@staticmethod
|
||||
def _generate_messages_from_queue(queue_message):
|
||||
last = queue_message['value'][-1]
|
||||
for message in queue_message['value']:
|
||||
last = queue_message['messages'][-1]
|
||||
for message in queue_message['messages']:
|
||||
yield {
|
||||
'key': 'message.send',
|
||||
'typing': message is not last,
|
||||
|
@ -37,7 +37,7 @@ def handler():
|
||||
def queue():
|
||||
yield {
|
||||
'key': 'message.queue',
|
||||
'value': [
|
||||
'messages': [
|
||||
{'originator': urandom(4).hex(), 'message': urandom(16).hex()}
|
||||
for _ in range(randint(5, 10))
|
||||
]
|
||||
@ -46,7 +46,7 @@ def queue():
|
||||
|
||||
def test_message_order(handler, queue):
|
||||
handler.connector.raise_event(queue)
|
||||
old_list = queue['value']
|
||||
old_list = queue['messages']
|
||||
new_list = handler.connector.messages
|
||||
length = len(old_list)
|
||||
assert len(new_list) == length
|
||||
@ -64,4 +64,4 @@ def test_wpm(handler, queue):
|
||||
handler.wpm = 100000000
|
||||
handler.connector.raise_event(queue)
|
||||
sleep(0.25)
|
||||
assert len(handler.connector.messages) == 2*len(queue['value'])
|
||||
assert len(handler.connector.messages) == 2*len(queue['messages'])
|
||||
|
@ -14,13 +14,13 @@ class MessageSender:
|
||||
def queue_messages(self, messages, originator=None):
|
||||
message_queue = {
|
||||
'key': 'message.queue',
|
||||
'value': []
|
||||
'messages': []
|
||||
}
|
||||
for message in messages:
|
||||
next_message = {'message': message}
|
||||
if originator:
|
||||
next_message['originator'] = originator
|
||||
message_queue['value'].append(next_message)
|
||||
message_queue['messages'].append(next_message)
|
||||
self.uplink.send_message(message_queue)
|
||||
|
||||
def set_originator(self, originator):
|
||||
|
@ -18,8 +18,8 @@ class FSMHandler:
|
||||
self.auth_key = KeyManager().auth_key
|
||||
|
||||
self.command_handlers = {
|
||||
'fsm.step' : self.handle_step,
|
||||
'fsm.update' : self.handle_update
|
||||
'fsm.trigger': self.handle_step,
|
||||
'fsm.update' : self.handle_update
|
||||
}
|
||||
|
||||
def handle_event(self, message, _):
|
||||
@ -32,7 +32,7 @@ class FSMHandler:
|
||||
except KeyError:
|
||||
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
||||
|
||||
def handle_step(self, message): # pylint: disable=inconsistent-return-statements
|
||||
def handle_trigger(self, message): # pylint: disable=inconsistent-return-statements
|
||||
if self.fsm.step(message['trigger']):
|
||||
return message
|
||||
|
||||
|
@ -58,7 +58,7 @@ class HistoryMonitor(ABC, InotifyObserver):
|
||||
def send_message(self, command):
|
||||
self.uplink.send_message({
|
||||
'key': f'history.{self.domain}',
|
||||
'value': command
|
||||
'command': command
|
||||
}, intent=Intent.EVENT)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user