Esempio n. 1
0
    def get(self, queue, message_id, project):
        if project is None:
            project = ''

        mid = utils.msgid_decode(message_id)
        if mid is None:
            raise exceptions.MessageDoesNotExist(message_id, queue, project)

        try:
            content, ttl, age = self.driver.get(
                '''
                select content, ttl, julianday() * 86400.0 - created
                  from Queues as Q join Messages as M
                    on qid = Q.id
                 where ttl > julianday() * 86400.0 - created
                   and M.id = ? and project = ? and name = ?
                ''', mid, project, queue)

        except utils.NoResult:
            raise exceptions.MessageDoesNotExist(message_id, queue, project)

        return {
            'id': message_id,
            'ttl': ttl,
            'age': int(age),
            'body': content,
        }
Esempio n. 2
0
    def delete(self, queue, message_id, project, claim=None):
        if project is None:
            project = ''

        id = utils.msgid_decode(message_id)
        if id is None:
            return

        with self.driver('immediate'):
            message_exists, = self.driver.get(
                '''
                select count(M.id)
                  from Queues as Q join Messages as M
                    on qid = Q.id
                 where ttl > julianday() * 86400.0 - created
                   and M.id = ? and project = ? and name = ?
            ''', id, project, queue)

            if not message_exists:
                return

            if claim is None:
                self.__delete_unclaimed(id)
            else:
                self.__delete_claimed(id, claim)
Esempio n. 3
0
    def get(self, queue, message_ids, project):
        if project is None:
            project = ''

        if isinstance(message_ids, six.string_types):
            message_ids = [message_ids]

        message_ids = ["'%s'" % utils.msgid_decode(id) for id in message_ids]
        message_ids = ','.join(message_ids)

        sql = '''
            select M.id, content, ttl, julianday() * 86400.0 - created
              from Queues as Q join Messages as M
                on qid = Q.id
             where ttl > julianday() * 86400.0 - created
               and M.id in (%s) and project = ? and name = ?
        ''' % message_ids

        records = self.driver.run(sql, project, queue)
        for id, content, ttl, age in records:
            yield {
                'id': utils.msgid_encode(id),
                'ttl': ttl,
                'age': int(age),
                'body': content,
            }
Esempio n. 4
0
    def delete(self, queue, message_id, project, claim=None):
        if project is None:
            project = ''

        id = utils.msgid_decode(message_id)

        if not claim:
            self.driver.run('''
                delete from Messages
                 where id = ?
                   and qid = (select id from Queues
                               where project = ? and name = ?)
            ''', id, project, queue)
            return

        with self.driver('immediate'):
            message_exists, = self.driver.get('''
                select count(M.id)
                  from Queues as Q join Messages as M
                    on qid = Q.id
                 where ttl > julianday() * 86400.0 - created
                   and M.id = ? and project = ? and name = ?
            ''', id, project, queue)

            if not message_exists:
                return

            self.__delete_claimed(id, claim)
Esempio n. 5
0
    def get(self, queue, message_id, project):
        if project is None:
            project = ''

        mid = utils.msgid_decode(message_id)
        if mid is None:
            raise exceptions.MessageDoesNotExist(message_id, queue, project)

        try:
            content, ttl, age = self.driver.get('''
                select content, ttl, julianday() * 86400.0 - created
                  from Queues as Q join Messages as M
                    on qid = Q.id
                 where ttl > julianday() * 86400.0 - created
                   and M.id = ? and project = ? and name = ?
                ''', mid, project, queue)

        except utils.NoResult:
            raise exceptions.MessageDoesNotExist(message_id, queue, project)

        return {
            'id': message_id,
            'ttl': ttl,
            'age': int(age),
            'body': content,
        }
Esempio n. 6
0
    def bulk_delete(self, queue, message_ids, project):
        if project is None:
            project = ''

        message_ids = ','.join(["'%s'" % utils.msgid_decode(id)
                                for id in message_ids])

        self.driver.run('''
            delete from Messages
             where id in (%s)
               and qid = (select id from Queues
                           where project = ? and name = ?)
        ''' % message_ids, project, queue)