Ensure queue exists before get/update the claim
Now with redis backend, if the queue is deleted, the request to claim is still work and will return some unexpected result, such as 503 error. So we should ensure the queue exists before get/update the claim. Change-Id: I324e342b0ec49ca2b6aa48e371fc818a53ac1ffb Closes-bug: #1591921
This commit is contained in:
parent
d0a129f26e
commit
0966c7a724
@ -118,6 +118,14 @@ class ClaimController(storage.Claim, scripting.Mixin):
|
||||
client = self._client
|
||||
claims_set_key = utils.scope_claims_set(queue, project,
|
||||
QUEUE_CLAIMS_SUFFIX)
|
||||
# In some cases, the queue maybe doesn't exist. So we should check
|
||||
# whether the queue exists. Return False if no such queue exists.
|
||||
|
||||
# Todo(flwang): We should delete all related data after the queue is
|
||||
# deleted. See the blueprint for more detail:
|
||||
# https://blueprints.launchpad.net/zaqar/+spec/clear-resources-after-delete-queue
|
||||
if not self._queue_ctrl._exists(queue, project):
|
||||
return False
|
||||
|
||||
# Return False if no such claim exists
|
||||
# TODO(prashanthr_): Discuss the feasibility of a bloom filter.
|
||||
|
@ -400,6 +400,20 @@ class RedisClaimsTest(base.ClaimControllerTest):
|
||||
self.controller.update, queue_name,
|
||||
claim_id, {}, project=None)
|
||||
|
||||
# create a claim and then delete the queue
|
||||
claim_id, messages = self.controller.create(queue_name, {'ttl': 100,
|
||||
'grace': 0},
|
||||
project=None)
|
||||
self.queue_controller.delete(queue_name)
|
||||
|
||||
self.assertRaises(storage.errors.ClaimDoesNotExist,
|
||||
self.controller.get, queue_name,
|
||||
claim_id, project=None)
|
||||
|
||||
self.assertRaises(storage.errors.ClaimDoesNotExist,
|
||||
self.controller.update, queue_name,
|
||||
claim_id, {}, project=None)
|
||||
|
||||
def test_get_claim_after_expires(self):
|
||||
queue_name = 'no-such-claim'
|
||||
self.queue_controller.create(queue_name, project='fake_project')
|
||||
|
Loading…
Reference in New Issue
Block a user