mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 02:31:56 +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
|
||||
return
|
||||
LOG.debug(event)
|
||||
key = 'webide'
|
||||
self.uplink.send(key, {'data': {'command': 'reload'}})
|
||||
self.uplink.send({'key': 'webide',
|
||||
'data': {'command': 'reload'}})
|
||||
|
||||
|
||||
def with_monitor_paused(fun):
|
||||
|
@ -19,9 +19,10 @@ class EventHandlerBase(ABC):
|
||||
def event_handler_callback(self, msg_parts):
|
||||
key, message = deserialize_all(*msg_parts)
|
||||
response = self.dispatch_handling(key, message)
|
||||
response['key'] = key
|
||||
if response is None:
|
||||
return
|
||||
self.server_connector.send(key, response)
|
||||
self.server_connector.send(response)
|
||||
|
||||
@abstractmethod
|
||||
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.connect('tcp://localhost:{}'.format(TFWENV.RECEIVER_PORT))
|
||||
|
||||
def send_to_eventhandler(self, key, message):
|
||||
message['data']['key'] = key
|
||||
self.send('mirror', message)
|
||||
def send_to_eventhandler(self, message):
|
||||
message['data']['key'] = message['key']
|
||||
message['key'] = 'mirror'
|
||||
self.send(message)
|
||||
|
||||
def send(self, key, message):
|
||||
message['key'] = key
|
||||
self._zmq_push_socket.send_multipart(serialize_all(key, message))
|
||||
def send(self, message):
|
||||
self._zmq_push_socket.send_multipart(serialize_all(message['key'], message))
|
||||
|
||||
|
||||
class ServerConnector(ServerUplinkConnector, ServerDownlinkConnector):
|
||||
|
@ -17,5 +17,5 @@ class MessageSender:
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'message': message
|
||||
}
|
||||
response = {'data': data}
|
||||
self.server_connector.send(self.key, response)
|
||||
self.server_connector.send({'key': self.key,
|
||||
'data': data})
|
||||
|
@ -100,12 +100,11 @@ class FSMUpdater:
|
||||
|
||||
def update(self, kwargs_dict):
|
||||
# pylint: disable=unused-argument
|
||||
self.uplink.send(*self.generate_fsm_update())
|
||||
self.uplink.send(self.generate_fsm_update())
|
||||
|
||||
def generate_fsm_update(self):
|
||||
key = 'FSMUpdate'
|
||||
response = {'data': self.get_fsm_state_and_transitions()}
|
||||
return key, response
|
||||
return {'key': 'FSMUpdate',
|
||||
'data': self.get_fsm_state_and_transitions()}
|
||||
|
||||
def get_fsm_state_and_transitions(self):
|
||||
state = self.fsm.state
|
||||
|
Loading…
Reference in New Issue
Block a user