Ejemplo n.º 1
0
    def delete_queue(self, queue_name):
        """
        Deletes a queue

        :param queue_name: The name of the queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)

        try:
            href = proc_template(self.queue_href, queue_name=queue_name)
            self._perform_http(href=href, method='DELETE')

        except ClientException as ex:
            raise NoSuchQueueError(queue_name) if ex.http_status == 404 else ex
Ejemplo n.º 2
0
    def get_messages(self, echo=False, restart=False):
        """
        TODO(jdp): Comment me
        """
        if not self._get_messages_href or restart:
            self._get_messages_href = proc_template(self._conn.messages_href,
                                                    queue_name=self.name)

            if echo:
                self._get_messages_href += "?echo=true"

        truncated = True  # Was the current request truncated?

        while truncated:
            truncated = False

            hdrs, body = self._conn._perform_http(href=self._get_messages_href,
                                                  method='GET')

            if not body:
                # Empty body, just short-circuit and return
                return

            for link in body['links']:
                if link['rel'] == 'next':
                    self._get_messages_href = link['href']
                    truncated = True

            for message in body['messages']:
                yield Message(self._conn,
                              href=message['href'],
                              content=message)
Ejemplo n.º 3
0
    def get_stats(self):
        """Retrieves statistics about the queue"""
        href = proc_template(self._conn.stats_href, queue_name=self._name)

        hdrs, body = self._conn._perform_http(href=href, method='GET')

        return Stats(body)
Ejemplo n.º 4
0
    def get_queue_metadata(self, queue_name):
        href = proc_template(self._queue_href, queue_name=queue_name)

        try:
            return self._perform_http(conn, href, 'GET')
        except ClientException as ex:
            raise NoSuchQueueError(queue_name) if ex.http_status == 404 else ex
Ejemplo n.º 5
0
    def get_queue_metadata(self, queue_name):
        href = proc_template(self._queue_href, queue_name=queue_name)

        try:
            return self._perform_http(conn, href, 'GET')
        except ClientException as ex:
            raise NoSuchQueueError(queue_name) if ex.http_status == 404 else ex
Ejemplo n.º 6
0
    def get_stats(self):
        """Retrieves statistics about the queue"""
        href = proc_template(self._conn.stats_href, queue_name=self._name)

        hdrs, body = self._conn._perform_http(href=href, method='GET')

        return Stats(body)
Ejemplo n.º 7
0
    def get_messages(self, echo=False, restart=False):
        """
        TODO(jdp): Comment me
        """
        if not self._get_messages_href or restart:
            self._get_messages_href = proc_template(self._conn.messages_href,
                                                    queue_name=self.name)

            if echo:
                self._get_messages_href += "?echo=true"

        truncated = True  # Was the current request truncated?

        while truncated:
            truncated = False

            hdrs, body = self._conn._perform_http(
                href=self._get_messages_href, method='GET')

            if not body:
                # Empty body, just short-circuit and return
                return

            for link in body['links']:
                if link['rel'] == 'next':
                    self._get_messages_href = link['href']
                    truncated = True

            for message in body['messages']:
                yield Message(self._conn,
                              href=message['href'],
                              content=message)
Ejemplo n.º 8
0
    def delete_queue(self, queue_name):
        """
        Deletes a queue

        :param queue_name: The name of the queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)
        self._perform_http(href=href, method='DELETE')
Ejemplo n.º 9
0
    def delete_queue(self, queue_name):
        """
        Deletes a queue

        :param queue_name: The name of the queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)
        self._perform_http(href=href, method='DELETE')
Ejemplo n.º 10
0
    def create_queue(self, queue_name, ttl):
        """
        Creates a queue with the specified name

        :param queue_name: The name of the queue
        :param ttl: The default time-to-live for messages in this queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)
        body = {u'messages': {u'ttl': ttl}}

        self._perform_http(href=href, method='PUT', request_body=body)

        return Queue(self, href=href, name=queue_name, metadata=body)
Ejemplo n.º 11
0
    def create_queue(self, queue_name):
        """
        Creates a queue with the specified name

        :param queue_name: The name of the queue
        :param ttl: The default time-to-live for messages in this queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)
        body = {}

        self._perform_http(href=href, method='PUT', request_body=body)

        return Queue(self, href=href, name=queue_name, metadata=body)
Ejemplo n.º 12
0
    def get_queue(self, queue_name):
        """
        Gets a queue by name

        :param queue_name: The name of the queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)

        try:
            hdrs, body = self._perform_http(href=href, method='GET')
        except ClientException as ex:
            raise NoSuchQueueError(queue_name) if ex.http_status == 404 else ex

        return Queue(self, href=href, name=queue_name, metadata=body)
Ejemplo n.º 13
0
    def get_queue(self, queue_name):
        """
        Gets a queue by name

        :param queue_name: The name of the queue
        """
        href = proc_template(self.queue_href, queue_name=queue_name)

        try:
            hdrs, body = self._perform_http(href=href, method='GET')
        except ClientException as ex:
            raise NoSuchQueueError(queue_name) if ex.http_status == 404 else ex

        return Queue(self, href=href, name=queue_name, metadata=body)
Ejemplo n.º 14
0
    def post_message(self, message, ttl):
        """
        Posts a single message with the specified ttl
        :param ttl: The TTL to set on this message
        """
        href = proc_template(self._conn.messages_href, queue_name=self.name)

        body = [{"ttl": ttl, "body": message}]

        hdrs, body = self._conn._perform_http(
            href=href, method='POST', request_body=body)

        location = hdrs['location']

        return Message(conn=self._conn, href=location)
Ejemplo n.º 15
0
    def post_message(self, message, ttl):
        """
        Posts a single message with the specified ttl
        :param ttl: The TTL to set on this message
        """
        href = proc_template(self._conn.messages_href, queue_name=self.name)

        body = [{"ttl": ttl, "body": message}]

        hdrs, body = self._conn._perform_http(href=href,
                                              method='POST',
                                              request_body=body)

        location = hdrs['location']

        return Message(conn=self._conn, href=location)
Ejemplo n.º 16
0
    def claim(self, ttl, grace, limit=5):
        """
        Claims a set of messages. The server configuration determines
        the maximum number of messages that can be claimed.
        """
        href = proc_template(self._claims_template, limit=limit)

        body = {"ttl": ttl, "grace": grace}

        hdrs, body = self._conn._perform_http(
            href=href, method='POST', request_body=body)

        # Build a list of Message objects using a list comprehesion
        msgs = [Message(self._conn, href=msg[
                        'href'], content=msg) for msg in body]

        location = hdrs['location']

        return Claim(conn=self._conn, messages=msgs, href=location)
Ejemplo n.º 17
0
    def claim(self, ttl, grace, limit=5):
        """
        Claims a set of messages. The server configuration determines
        the maximum number of messages that can be claimed.
        """
        href = proc_template(self._claims_template, limit=str(limit))

        body = {"ttl": ttl, "grace": grace}

        hdrs, body = self._conn._perform_http(href=href,
                                              method='POST',
                                              request_body=body)

        # Build a list of Message objects using a list comprehesion
        msgs = [
            Message(self._conn, href=msg['href'], content=msg) for msg in body
        ]

        location = hdrs['location']

        return Claim(conn=self._conn, messages=msgs, href=location)
Ejemplo n.º 18
0
    def get_message(self, message_id):

        href = proc_template(self._conn.message_href, message_id)
Ejemplo n.º 19
0
 def get_queue_metadata(self, queue_name):
     href = proc_template(self._queue_href, queue_name=queue_name)
     return self._perform_http(conn, href, 'GET')
Ejemplo n.º 20
0
    def get_message(self, message_id):

        href = proc_template(self._conn.message_href, message_id)