mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:01:31 +00:00
Refactor ServerUplinkConnector.send() signature
This commit is contained in:
parent
b8cdb30318
commit
d04479157d
@ -70,8 +70,8 @@ class WebideReloadWatchdogEventHandler(FileSystemWatchdogEventHandler):
|
|||||||
self.ignore = self.ignore - 1
|
self.ignore = self.ignore - 1
|
||||||
return
|
return
|
||||||
LOG.debug(event)
|
LOG.debug(event)
|
||||||
key = 'webide'
|
self.uplink.send({'key': 'webide',
|
||||||
self.uplink.send(key, {'data': {'command': 'reload'}})
|
'data': {'command': 'reload'}})
|
||||||
|
|
||||||
|
|
||||||
def with_monitor_paused(fun):
|
def with_monitor_paused(fun):
|
||||||
|
@ -19,9 +19,10 @@ class EventHandlerBase(ABC):
|
|||||||
def event_handler_callback(self, msg_parts):
|
def event_handler_callback(self, msg_parts):
|
||||||
key, message = deserialize_all(*msg_parts)
|
key, message = deserialize_all(*msg_parts)
|
||||||
response = self.dispatch_handling(key, message)
|
response = self.dispatch_handling(key, message)
|
||||||
|
response['key'] = key
|
||||||
if response is None:
|
if response is None:
|
||||||
return
|
return
|
||||||
self.server_connector.send(key, response)
|
self.server_connector.send(response)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def dispatch_handling(self, key, message):
|
def dispatch_handling(self, key, message):
|
||||||
|
@ -29,13 +29,13 @@ class ServerUplinkConnector(ZMQConnectorBase):
|
|||||||
self._zmq_push_socket = self._zmq_context.socket(zmq.PUSH)
|
self._zmq_push_socket = self._zmq_context.socket(zmq.PUSH)
|
||||||
self._zmq_push_socket.connect('tcp://localhost:{}'.format(TFWENV.RECEIVER_PORT))
|
self._zmq_push_socket.connect('tcp://localhost:{}'.format(TFWENV.RECEIVER_PORT))
|
||||||
|
|
||||||
def send_to_eventhandler(self, key, message):
|
def send_to_eventhandler(self, message):
|
||||||
message['data']['key'] = key
|
message['data']['key'] = message['key']
|
||||||
self.send('mirror', message)
|
message['key'] = 'mirror'
|
||||||
|
self.send(message)
|
||||||
|
|
||||||
def send(self, key, message):
|
def send(self, message):
|
||||||
message['key'] = key
|
self._zmq_push_socket.send_multipart(serialize_all(message['key'], message))
|
||||||
self._zmq_push_socket.send_multipart(serialize_all(key, message))
|
|
||||||
|
|
||||||
|
|
||||||
class ServerConnector(ServerUplinkConnector, ServerDownlinkConnector):
|
class ServerConnector(ServerUplinkConnector, ServerDownlinkConnector):
|
||||||
|
@ -17,5 +17,5 @@ class MessageSender:
|
|||||||
'timestamp': datetime.now().isoformat(),
|
'timestamp': datetime.now().isoformat(),
|
||||||
'message': message
|
'message': message
|
||||||
}
|
}
|
||||||
response = {'data': data}
|
self.server_connector.send({'key': self.key,
|
||||||
self.server_connector.send(self.key, response)
|
'data': data})
|
||||||
|
@ -100,12 +100,11 @@ class FSMUpdater:
|
|||||||
|
|
||||||
def update(self, kwargs_dict):
|
def update(self, kwargs_dict):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
self.uplink.send(*self.generate_fsm_update())
|
self.uplink.send(self.generate_fsm_update())
|
||||||
|
|
||||||
def generate_fsm_update(self):
|
def generate_fsm_update(self):
|
||||||
key = 'FSMUpdate'
|
return {'key': 'FSMUpdate',
|
||||||
response = {'data': self.get_fsm_state_and_transitions()}
|
'data': self.get_fsm_state_and_transitions()}
|
||||||
return key, response
|
|
||||||
|
|
||||||
def get_fsm_state_and_transitions(self):
|
def get_fsm_state_and_transitions(self):
|
||||||
state = self.fsm.state
|
state = self.fsm.state
|
||||||
|
Loading…
Reference in New Issue
Block a user