Пример #1
0
def stat_message(message, now):
    """Creates a stat document from the given message, relative to now."""
    oid = message["_id"]
    created = oid_ts(oid)
    age = now - created

    return {"id": str(oid), "age": int(age), "created": timeutils.iso8601_from_timestamp(created)}
Пример #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 stat_message(message, now):
    """Creates a stat document from the given message, relative to now."""
    oid = message['_id']
    created = oid_ts(oid)
    age = now - created

    return {
        'id': str(oid),
        'age': int(age),
        'created': timeutils.iso8601_from_timestamp(created),
    }
Пример #4
0
def stat_message(message, now):
    """Creates a stat document from the given message, relative to now."""
    oid = message['_id']
    created = oid_ts(oid)
    age = now - created

    return {
        'id': str(oid),
        'age': int(age),
        'created': timeutils.iso8601_from_timestamp(created),
    }
Пример #5
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,
            }
Пример #6
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,
            }