def denormalizer(msg): oid = msg['_id'] age = now - utils.oid_utc(oid) return { 'id': str(oid), 'age': age.seconds, 'ttl': msg['t'], 'body': msg['b'], }
def _basic_message(msg, now): oid = msg['_id'] age = timeutils.delta_seconds(utils.oid_utc(oid), now) return { 'id': str(oid), 'age': int(age), 'ttl': msg['t'], 'body': msg['b'], }
def get(self, queue, claim_id, project=None): msg_ctrl = self.driver.message_controller # Check whether the queue exists or not qid = self._get_queue_id(queue, project) # Base query, always check expire time now = timeutils.utcnow() try: cid = utils.to_oid(claim_id) except ValueError: raise exceptions.ClaimDoesNotExist() age = now - utils.oid_utc(cid) def messages(msg_iter): msg = next(msg_iter) yield msg.pop('claim') yield msg # Smoke it! for msg in msg_iter: del msg['claim'] yield msg try: # Lets get claim's data # from the first message # in the iterator messages = messages(msg_ctrl.claimed(qid, cid, now)) claim = next(messages) claim = { 'age': age.seconds, 'ttl': claim.pop('t'), 'id': str(claim['id']), } except StopIteration: raise exceptions.ClaimDoesNotExist(cid, queue, project) return (claim, messages)
def _basic_message(msg, now): oid = msg["_id"] age = timeutils.delta_seconds(utils.oid_utc(oid), now) return {"id": str(oid), "age": int(age), "ttl": msg["t"], "body": msg["b"]}