예제 #1
0
    def messages(self, queue_name, partition=1, since=None, limit=100,
                  order='ascending'):
        """Returns messages for a queue, by default from oldest to newest.

        :param queue_name: Queue name
        :type queue_name: unicode
        :param partition: Partition number, defaults to 1.
        :type partition: int
        :param since: Only return messages after (not including) a given
            message id, defaults to no restriction.
        :type since: str
        :param limit: Only return N number of messages, defaults to 100.
        :type limit: int
        :param order: 'descending' or 'ascending', defaults to ascending
        :type order: str
        :raises: :py:exc:`queuey_py.client.HTTPError`
        :rtype: list
        """
        params = {
            u'limit': limit,
            u'order': order,
            u'partitions': partition,
        }
        if since:
            params[u'since'] = since
        response = self.get(queue_name, params=params)
        if response.ok:
            messages = ujson_decode(response.text)[u'messages']
            # filter out exact timestamp matches
            return [m for m in messages if m[u'message_id'] != since]
        # failure
        raise HTTPError(response.status_code, response)
 def _clean_queuey(cls):
     conn = cls._queuey_conn
     try:
         response = conn.get()
         queues = ujson_decode(response.text)['queues']
         names = [q['queue_name'] for q in queues]
         for n in names:
             conn.delete(n)
     except ConnectionError:
         pass
예제 #3
0
 def _clean_queuey(cls):
     conn = cls._queuey_conn
     try:
         response = conn.get()
         queues = ujson_decode(response.text)['queues']
         names = [q['queue_name'] for q in queues]
         for n in names:
             conn.delete(n)
     except ConnectionError:
         pass
예제 #4
0
 def all_partitions(self):
     # List all partitions
     queuey_conn = self.queuey_conn
     response = queuey_conn.get(params={'details': True})
     queues = ujson_decode(response.text)['queues']
     partitions = []
     for q in queues:
         name = q['queue_name']
         part = q['partitions']
         for i in xrange(1, part + 1):
             partitions.append('%s-%s' % (name, i))
     return partitions
 def all_partitions(self):
     # List all partitions
     queuey_conn = self.queuey_conn
     response = queuey_conn.get(params={'details': True})
     queues = ujson_decode(response.text)['queues']
     partitions = []
     for q in queues:
         name = q['queue_name']
         part = q['partitions']
         for i in xrange(1, part + 1):
             partitions.append('%s-%s' % (name, i))
     return partitions
예제 #6
0
 def status_partitions(self):
     status = {}
     # get all status messages, starting with the newest ones
     status_messages = self.queuey_conn.messages(
         STATUS_QUEUE, limit=1000, order='descending')
     if len(status_messages) >= 1000:  # pragma: no cover
         # TODO deal with more than 1000 status messages / partitions
         raise RuntimeError('More than 1000 status messages detected!')
     for message in status_messages:
         body = ujson_decode(message['body'])
         partition = body['partition']
         if partition not in status:
             # don't overwrite newer messages with older status
             status[partition] = message['message_id']
     return status
 def status_partitions(self):
     status = {}
     # get all status messages, starting with the newest ones
     status_messages = self.queuey_conn.messages(STATUS_QUEUE,
                                                 limit=1000,
                                                 order='descending')
     if len(status_messages) >= 1000:  # pragma: no cover
         # TODO deal with more than 1000 status messages / partitions
         raise RuntimeError('More than 1000 status messages detected!')
     for message in status_messages:
         body = ujson_decode(message['body'])
         partition = body['partition']
         if partition not in status:
             # don't overwrite newer messages with older status
             status[partition] = message['message_id']
     return status
    def messages(self,
                 queue_name,
                 partition=1,
                 since=None,
                 limit=100,
                 order='ascending'):
        """Returns messages for a queue, by default from oldest to newest.

        :param queue_name: Queue name
        :type queue_name: unicode
        :param partition: Partition number, defaults to 1.
        :type partition: int
        :param since: Only return messages after (not including) a given
            message id, defaults to no restriction.
        :type since: str
        :param limit: Only return N number of messages, defaults to 100.
        :type limit: int
        :param order: 'descending' or 'ascending', defaults to ascending
        :type order: str
        :raises: :py:exc:`queuey_py.client.HTTPError`
        :rtype: list
        """
        params = {
            u'limit': limit,
            u'order': order,
            u'partitions': partition,
        }
        if since:
            params[u'since'] = since
        response = self.get(queue_name, params=params)
        if response.ok:
            messages = ujson_decode(response.text)[u'messages']
            # filter out exact timestamp matches
            return [m for m in messages if m[u'message_id'] != since]
        # failure
        raise HTTPError(response.status_code, response)