Count "claimed" and "free" msgs in Queue stats.
Change-Id: Ic8e2a4490d40a0745be458766bbe4c77220f6869
This commit is contained in:
parent
84b1f4bee2
commit
efcb1111af
@ -96,16 +96,14 @@ class QueueController(storage.QueueBase):
|
||||
def stats(self, name, tenant=None):
|
||||
qid = self.get_id(name, tenant)
|
||||
msg_ctrl = self.driver.message_controller
|
||||
total = msg_ctrl.all().count()
|
||||
active = msg_ctrl.active(qid).count()
|
||||
active = msg_ctrl.active(qid)
|
||||
claimed = msg_ctrl.claimed(qid)
|
||||
|
||||
return {
|
||||
"actions": 0,
|
||||
"messages": {
|
||||
"total": total,
|
||||
"expired": total - active,
|
||||
"claimed": claimed.count(),
|
||||
"free": active.count(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,27 +73,25 @@ class Queue(base.QueueBase):
|
||||
def stats(self, name, tenant):
|
||||
with self.driver('deferred'):
|
||||
qid = _get_qid(self.driver, name, tenant)
|
||||
total, expired, claimed = self.driver.get('''
|
||||
claimed, free = self.driver.get('''
|
||||
select * from
|
||||
(select count(id)
|
||||
from Messages
|
||||
where qid = ?),
|
||||
(select count(id)
|
||||
from Messages
|
||||
where ttl <= julianday() * 86400.0 - created
|
||||
and qid = ?),
|
||||
(select count(msgid)
|
||||
from Claims join Locked
|
||||
on id = cid
|
||||
where ttl > julianday() * 86400.0 - created
|
||||
and qid = ?),
|
||||
(select count(id)
|
||||
from Messages left join Locked
|
||||
on id = msgid
|
||||
where msgid is null
|
||||
and ttl > julianday() * 86400.0 - created
|
||||
and qid = ?)
|
||||
''', qid, qid, qid)
|
||||
''', qid, qid)
|
||||
|
||||
return {
|
||||
'messages': {
|
||||
'claimed': claimed,
|
||||
'expired': expired,
|
||||
'total': total,
|
||||
'free': free,
|
||||
},
|
||||
'actions': 0,
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ class QueueControllerTest(ControllerBaseTest):
|
||||
tenant=self.tenant, client_uuid="my_uuid", num=12)
|
||||
|
||||
countof = self.controller.stats("test", tenant=self.tenant)
|
||||
self.assertEqual(countof['messages']['total'], 12)
|
||||
self.assertEqual(countof['messages']['free'], 12)
|
||||
|
||||
# Test Queue Deletion
|
||||
self.controller.delete("test", tenant=self.tenant)
|
||||
@ -217,6 +217,12 @@ class ClaimControllerTest(ControllerBaseTest):
|
||||
messages = list(messages)
|
||||
self.assertEquals(len(messages), 15)
|
||||
|
||||
# Ensure Queue stats
|
||||
countof = self.queue_controller.stats(self.queue_name,
|
||||
tenant=self.tenant)
|
||||
self.assertEqual(countof['messages']['claimed'], 15)
|
||||
self.assertEqual(countof['messages']['free'], 5)
|
||||
|
||||
# Make sure get works
|
||||
claim, messages2 = self.controller.get(self.queue_name, claim_id,
|
||||
tenant=self.tenant)
|
||||
|
@ -64,7 +64,7 @@ class TestSqlite(testing.TestBase):
|
||||
|
||||
# ensure the message counts
|
||||
countof = self.queue_ctrl.stats('fizbit', '480924')
|
||||
self.assertEquals(countof['messages']['total'], 11)
|
||||
self.assertEquals(countof['messages']['free'], 1)
|
||||
self.assertEquals(countof['messages']['claimed'], 10)
|
||||
|
||||
# claim a message
|
||||
@ -113,7 +113,7 @@ class TestSqlite(testing.TestBase):
|
||||
self.msg_ctrl.get('fizbit', msgid, '480924')
|
||||
|
||||
countof = self.queue_ctrl.stats('fizbit', '480924')
|
||||
self.assertEquals(countof['messages']['expired'], 1)
|
||||
self.assertEquals(countof['messages']['free'], 0)
|
||||
|
||||
#TODO(zyuan): move this to tests/storage/test_impl_sqlite.py
|
||||
def test_illformed_id(self):
|
||||
|
@ -166,7 +166,7 @@ class TestMessages(util.TestBase):
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_200)
|
||||
self.assertEquals(self.srmock.headers_dict['Content-Location'],
|
||||
env['PATH_INFO'])
|
||||
self.assertEquals(countof['messages']['total'], 10)
|
||||
self.assertEquals(countof['messages']['free'], 10)
|
||||
|
||||
env = testing.create_environ('/v1/480924/queues/nonexistent/messages',
|
||||
headers=self.headers)
|
||||
|
Loading…
x
Reference in New Issue
Block a user