示例#1
0
    def bulk_get(self, queue, message_ids, project):
        if project is None:
            project = ''

        message_ids = ','.join(
            ["'%s'" % id for id in
             map(utils.msgid_decode, message_ids) if id is not None]
        )

        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,
            }
示例#2
0
    def first(self, queue, project=None, sort=1):
        if project is None:
            project = ""

        with self.driver("deferred"):
            sql = """
                select id, content, ttl, created,
                       julianday() * 86400.0 - created
                  from Messages
                 where ttl > julianday() * 86400.0 - created
                   and qid = ?
              order by id %s
                 limit 1"""

            if sort not in (1, -1):
                raise ValueError(u"sort must be either 1 (ascending) " u"or -1 (descending)")

            sql = sql % ("DESC" if sort == -1 else "ASC")

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

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

            try:
                id, content, ttl, created, age = next(records)
            except StopIteration:
                raise errors.QueueIsEmpty(queue, project)

            created_unix = utils.julian_to_unix(created)
            created_iso8601 = timeutils.iso8601_from_timestamp(created_unix)

            return {"id": utils.msgid_encode(id), "ttl": ttl, "created": created_iso8601, "age": age, "body": content}
示例#3
0
    def bulk_get(self, queue, message_ids, project):
        if project is None:
            project = ''

        message_ids = ','.join([
            "'%s'" % id for id in map(utils.msgid_decode, message_ids)
            if id is not None
        ])

        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,
            }
示例#4
0
 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,
         }
示例#5
0
 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,
         }
示例#6
0
    def __get(self, cid):
        records = self.driver.run('''
            select id, content, ttl, julianday() * 86400.0 - created
              from Messages join Locked
                on msgid = id
             where ttl > julianday() * 86400.0 - created
               and cid = ?''', cid)

        for id, content, ttl, age in records:
            yield {
                'id': utils.msgid_encode(id),
                'ttl': ttl,
                'age': int(age),
                'body': content,
            }
示例#7
0
    def __get(self, cid):
        records = self.driver.run(
            '''
            select id, content, ttl, julianday() * 86400.0 - created
              from Messages join Locked
                on msgid = id
             where ttl > julianday() * 86400.0 - created
               and cid = ?''', cid)

        for id, content, ttl, age in records:
            yield {
                'id': utils.msgid_encode(id),
                'ttl': ttl,
                'age': int(age),
                'body': content,
            }
示例#8
0
    def bulk_get(self, queue, message_ids, project):
        if project is None:
            project = ""

        message_ids = ",".join(["'%s'" % id for id in map(utils.msgid_decode, message_ids) if id is not None])

        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}
示例#9
0
    def first(self, queue, project=None, sort=1):
        if project is None:
            project = ''

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

            if sort not in (1, -1):
                raise ValueError(u'sort must be either 1 (ascending) '
                                 u'or -1 (descending)')

            sql = sql % ('DESC' if sort == -1 else 'ASC')

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

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

            try:
                id, content, ttl, created, age = next(records)
            except StopIteration:
                raise errors.QueueIsEmpty(queue, project)

            created_unix = utils.julian_to_unix(created)
            created_iso8601 = timeutils.iso8601_from_timestamp(created_unix)

            return {
                'id': utils.msgid_encode(id),
                'ttl': ttl,
                'created': created_iso8601,
                'age': age,
                'body': content,
            }
示例#10
0
    def first(self, queue, project=None, sort=1):
        if project is None:
            project = ''

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

            if sort not in (1, -1):
                raise ValueError(u'sort must be either 1 (ascending) '
                                 u'or -1 (descending)')

            sql = sql % ('DESC' if sort == -1 else 'ASC')

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

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

            try:
                id, content, ttl, created, age = next(records)
            except StopIteration:
                raise exceptions.QueueIsEmpty(queue, project)

            created_unix = utils.julian_to_unix(created)
            created_iso8601 = timeutils.iso8601_from_timestamp(created_unix)

            return {
                'id': utils.msgid_encode(id),
                'ttl': ttl,
                'created': created_iso8601,
                'age': age,
                'body': content,
            }
示例#11
0
 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}