From 432abd47ec2ba171141cebe37b622e59d0e9332d Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Mon, 9 Jan 2017 10:58:23 +0100 Subject: [PATCH] Use pop for checking messages with websocket I1c94ad82c3b20cc331045c19d4a9987a701b081b fixed the issue in Zaqar where the pop argument was wrongly named. We can now use it in the zaqar collector to retrieve messages over websocket. Change-Id: I0ce894b0eef7018a37db9ef9d1b43d8d20629bf0 --- os_collect_config/zaqar.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/os_collect_config/zaqar.py b/os_collect_config/zaqar.py index e16f9ba..32f51a6 100644 --- a/os_collect_config/zaqar.py +++ b/os_collect_config/zaqar.py @@ -90,27 +90,19 @@ class Collector(object): 'ttl': 10000}) ws.send(req) - # TODO(dprince) would be nice to use message_delete_many but - # websockets doesn't support parameters so we can't send 'pop'. - # This would allow us to avoid the 'message_delete' below. Example: - # req = self._create_req(endpoint, 'message_delete_many', - # {'queue_name': CONF.zaqar.queue_id, 'pop': 1}) - req = self._create_req(endpoint, 'message_list', + # check for pre-existing messages + req = self._create_req(endpoint, 'message_delete_many', {'queue_name': CONF.zaqar.queue_id, - 'echo': True}) + 'pop': 1}) resp = ws.send(req) messages = json.loads(resp.content).get('messages', []) if len(messages) > 0: # NOTE(dprince) In this case we are checking for queue # messages that arrived before we subscribed. - logger.debug('Websocket message_list found...') + logger.debug('Websocket message found...') msg_0 = messages[0] data = msg_0['body'] - req = self._create_req(endpoint, 'message_delete', - {'queue_name': CONF.zaqar.queue_id, - 'message_id': msg_0['id']}) - ws.send(req) else: # NOTE(dprince) This will block until there is data available