Esempio n. 1
0
    def list(self,
             queue,
             project,
             marker=None,
             limit=None,
             echo=False,
             client_uuid=None,
             include_claimed=False):

        if limit is None:
            limit = CFG.default_message_paging

        if project is None:
            project = ''

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

            args = [queue, project]

            if not echo:
                sql += '''
                   and M.client != ?'''
                args += [client_uuid]

            if marker:
                sql += '''
                   and M.id > ?'''
                args += [utils.marker_decode(marker)]

            if not include_claimed:
                sql += '''
                   and M.id not in (select msgid
                                      from Claims join Locked
                                        on id = cid)'''

            sql += '''
                 limit ?'''
            args += [limit]

            records = self.driver.run(sql, *args)
            marker_id = {}

            def it():
                for id, content, ttl, age in records:
                    marker_id['next'] = id
                    yield {
                        'id': utils.msgid_encode(id),
                        'ttl': ttl,
                        'age': int(age),
                        'body': content,
                    }

            yield it()
            yield utils.marker_encode(marker_id['next'])
Esempio n. 2
0
    def list(self, queue, project, marker=None, limit=None,
             echo=False, client_uuid=None, include_claimed=False):

        if limit is None:
            limit = CFG.default_message_paging

        if project is None:
            project = ''

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

            args = [queue, project]

            if not echo:
                sql += '''
                   and M.client != ?'''
                args += [client_uuid]

            if marker:
                sql += '''
                   and M.id > ?'''
                args += [utils.marker_decode(marker)]

            if not include_claimed:
                sql += '''
                   and M.id not in (select msgid
                                      from Claims join Locked
                                        on id = cid)'''

            sql += '''
                 limit ?'''
            args += [limit]

            records = self.driver.run(sql, *args)
            marker_id = {}

            def it():
                for id, content, ttl, age in records:
                    marker_id['next'] = id
                    yield {
                        'id': utils.msgid_encode(id),
                        'ttl': ttl,
                        'age': int(age),
                        'body': content,
                    }

            yield it()
            yield utils.marker_encode(marker_id['next'])
Esempio n. 3
0
    def list(self, queue, project, marker=None, limit=10,
             echo=False, client_uuid=None, include_claimed=False):

        if project is None:
            project = ''

        with self.driver('deferred'):
            sql = '''
                select id, content, ttl, julianday() * 86400.0 - created
                  from Messages
                 where ttl > julianday() * 86400.0 - created
                   and qid = ?'''

            args = [utils.get_qid(self.driver, queue, project)]

            if not echo:
                sql += '''
                   and client != ?'''
                args += [client_uuid]

            if marker:
                sql += '''
                   and id > ?'''
                args += [utils.marker_decode(marker)]

            if not include_claimed:
                sql += '''
                    and id not in (select msgid
                                     from Claims join Locked
                                       on id = cid)'''

            sql += '''
                 limit ?'''
            args += [limit]

            records = self.driver.run(sql, *args)
            marker_id = {}

            def it():
                for id, content, ttl, age in records:
                    marker_id['next'] = id
                    yield {
                        'id': utils.msgid_encode(id),
                        'ttl': ttl,
                        'age': int(age),
                        'body': content,
                    }

            yield it()
            yield utils.marker_encode(marker_id['next'])