Refactor ServerUplinkConnector to avoid passing redundant data

This commit is contained in:
Kristóf Tóth 2018-02-28 15:57:44 +01:00
parent 9eaced9f02
commit e29b300925
5 changed files with 5 additions and 10 deletions

View File

@ -25,8 +25,7 @@ class WebideReloadEventHandler(FileSystemEventHandler):
if self._paused: return if self._paused: return
log.debug(event) log.debug(event)
key = 'webide' key = 'webide'
self.uplink.send(key, {'key': key, self.uplink.send(key, {'data': {'command': 'reload'}})
'data': {'command': 'reload'}})
class DirectoryMonitor: class DirectoryMonitor:

View File

@ -25,5 +25,4 @@ class ProcessManagingEventHandler(TriggerlessEventHandler):
def handle_event(self, key, data_json): def handle_event(self, key, data_json):
data = data_json['data'] data = data_json['data']
self.processmanager(data['command'], data['process_name']) self.processmanager(data['command'], data['process_name'])
self.uplink.send(self.key, {'key': self.key, self.uplink.send(self.key, {'data': {'process_name': data['process_name']}})
'data': {'process_name': data['process_name']}})

View File

@ -14,8 +14,5 @@ class MessageSender:
'timestamp': datetime.now().isoformat(), 'timestamp': datetime.now().isoformat(),
'message': message 'message': message
} }
response = { response = {'data': data}
'key': self.key,
'data': data
}
self.server_connector.send(self.key, response) self.server_connector.send(self.key, response)

View File

@ -26,6 +26,7 @@ class ServerUplinkConnector(ZMQConnectorBase):
self._zmq_push_socket.connect('tcp://localhost:{}'.format(tfwenv.RECEIVER_PORT)) self._zmq_push_socket.connect('tcp://localhost:{}'.format(tfwenv.RECEIVER_PORT))
def send(self, key, response): def send(self, key, response):
response['key'] = key
self._zmq_push_socket.send_multipart(serialize_all(key, response)) self._zmq_push_socket.send_multipart(serialize_all(key, response))

View File

@ -46,8 +46,7 @@ class FSMUpdater:
def generate_fsm_update(self): def generate_fsm_update(self):
key = 'FSMUpdate' key = 'FSMUpdate'
response = {'key': key, response = {'data': {'current_state': self.fsm.state,
'data': {'current_state': self.fsm.state,
'valid_transitions': 'valid_transitions':
[{'trigger': trigger} for trigger in self.fsm.machine.get_triggers(self.fsm.state)]}} [{'trigger': trigger} for trigger in self.fsm.machine.get_triggers(self.fsm.state)]}}
return key, response return key, response