Browse Source

Merge "Use pop for checking messages with websocket"

Jenkins 2 years ago
parent
commit
0e2a8ab43a
1 changed files with 4 additions and 12 deletions
  1. 4
    12
      os_collect_config/zaqar.py

+ 4
- 12
os_collect_config/zaqar.py View File

@@ -90,27 +90,19 @@ class Collector(object):
90 90
                                     'ttl': 10000})
91 91
             ws.send(req)
92 92
 
93
-            # TODO(dprince) would be nice to use message_delete_many but
94
-            # websockets doesn't support parameters so we can't send 'pop'.
95
-            # This would allow us to avoid the 'message_delete' below. Example:
96
-            # req = self._create_req(endpoint, 'message_delete_many',
97
-            #     {'queue_name': CONF.zaqar.queue_id, 'pop': 1})
98
-            req = self._create_req(endpoint, 'message_list',
93
+            # check for pre-existing messages
94
+            req = self._create_req(endpoint, 'message_delete_many',
99 95
                                    {'queue_name': CONF.zaqar.queue_id,
100
-                                    'echo': True})
96
+                                    'pop': 1})
101 97
             resp = ws.send(req)
102 98
             messages = json.loads(resp.content).get('messages', [])
103 99
 
104 100
             if len(messages) > 0:
105 101
                 # NOTE(dprince) In this case we are checking for queue
106 102
                 # messages that arrived before we subscribed.
107
-                logger.debug('Websocket message_list found...')
103
+                logger.debug('Websocket message found...')
108 104
                 msg_0 = messages[0]
109 105
                 data = msg_0['body']
110
-                req = self._create_req(endpoint, 'message_delete',
111
-                                       {'queue_name': CONF.zaqar.queue_id,
112
-                                        'message_id': msg_0['id']})
113
-                ws.send(req)
114 106
 
115 107
             else:
116 108
                 # NOTE(dprince) This will block until there is data available

Loading…
Cancel
Save