Merge "Show 'age' field in subscriptions (redis)"
This commit is contained in:
commit
088c3f6310
@ -147,13 +147,14 @@ class SubscriptionEnvelope(object):
|
||||
pipe.hmset(self.id, hmap)
|
||||
pipe.expire(self.id, self.ttl)
|
||||
|
||||
def to_basic(self):
|
||||
def to_basic(self, now):
|
||||
created = self.expires - self.ttl
|
||||
basic_msg = {
|
||||
'id': self.id,
|
||||
'source': self.source,
|
||||
'subscriber': self.subscriber,
|
||||
'ttl': self.ttl,
|
||||
'expires': self.expires,
|
||||
'age': now - created,
|
||||
'options': self.options,
|
||||
}
|
||||
|
||||
|
@ -72,12 +72,17 @@ class SubscriptionController(base.Subscription):
|
||||
marker_next = {}
|
||||
|
||||
def denormalizer(record, sid):
|
||||
now = timeutils.utcnow_ts()
|
||||
ttl = int(record[2])
|
||||
expires = int(record[3])
|
||||
created = expires - ttl
|
||||
ret = {
|
||||
'id': sid,
|
||||
'source': record[0],
|
||||
'subscriber': record[1],
|
||||
'ttl': int(record[2]),
|
||||
'options': self._unpacker(record[3]),
|
||||
'ttl': ttl,
|
||||
'age': now - created,
|
||||
'options': self._unpacker(record[4]),
|
||||
}
|
||||
marker_next['next'] = sid
|
||||
|
||||
@ -89,11 +94,11 @@ class SubscriptionController(base.Subscription):
|
||||
@utils.raises_conn_error
|
||||
@utils.retries_on_connection_error
|
||||
def get(self, queue, subscription_id, project=None):
|
||||
|
||||
subscription = SubscriptionEnvelope.from_redis(subscription_id,
|
||||
self._client)
|
||||
if subscription:
|
||||
return subscription.to_basic()
|
||||
now = timeutils.utcnow_ts()
|
||||
return subscription.to_basic(now)
|
||||
else:
|
||||
raise errors.SubscriptionDoesNotExist(subscription_id)
|
||||
|
||||
|
@ -266,7 +266,7 @@ class SubscriptionListCursor(object):
|
||||
@raises_conn_error
|
||||
def next(self):
|
||||
curr = next(self.subscription_iter)
|
||||
subscription = self.client.hmget(curr, ['s', 'u', 't', 'o'])
|
||||
subscription = self.client.hmget(curr, ['s', 'u', 't', 'e', 'o'])
|
||||
# NOTE(flwang): The expired subscription will be removed
|
||||
# automatically, but the key can't be deleted automatically as well.
|
||||
# Though we clean up those expired ids when create new subscription,
|
||||
|
Loading…
x
Reference in New Issue
Block a user