mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 22:01:31 +00:00
Refactor FSMUpdate message sending logic to class FSMUpdater
This commit is contained in:
parent
940e74d6da
commit
cf4a5bc09d
@ -10,8 +10,9 @@ log = logging.getLogger(__name__)
|
||||
class TFWServer:
|
||||
def __init__(self, fsm_type):
|
||||
self._fsm = fsm_type()
|
||||
self.uplink = ServerUplinkConnector()
|
||||
self._fsm.subscribe(self.fsm_callback)
|
||||
self.fsm_updater = FSMUpdater(self._fsm)
|
||||
self._fsm.subscribe(self.fsm_updater.update)
|
||||
|
||||
self.application = Application(
|
||||
[(r'/ws', ZMQWebSocketProxy, {'make_response': self.make_response,
|
||||
'proxy_filter': self.proxy_filter})]
|
||||
@ -29,7 +30,16 @@ class TFWServer:
|
||||
try: return self.fsm.trigger(message['key'], message=message)
|
||||
except AttributeError: return False
|
||||
|
||||
def fsm_callback(self, kwargs_dict):
|
||||
def listen(self, port):
|
||||
self.application.listen(port)
|
||||
|
||||
|
||||
class FSMUpdater:
|
||||
def __init__(self, fsm):
|
||||
self.fsm = fsm
|
||||
self.uplink = ServerUplinkConnector()
|
||||
|
||||
def update(self, kwargs_dict):
|
||||
self.uplink.send(*self.generate_fsm_update())
|
||||
|
||||
def generate_fsm_update(self):
|
||||
@ -39,6 +49,3 @@ class TFWServer:
|
||||
'valid_transitions':
|
||||
[{'trigger': trigger} for trigger in self.fsm.machine.get_triggers(self.fsm.state)]}}
|
||||
return key, response
|
||||
|
||||
def listen(self, port):
|
||||
self.application.listen(port)
|
||||
|
Loading…
Reference in New Issue
Block a user