Merge "Reduce duplication in swift post messages"
This commit is contained in:
commit
5ff2d1a9be
@ -215,31 +215,15 @@ class MessageController(storage.Message):
|
|||||||
contents = jsonutils.dumps(
|
contents = jsonutils.dumps(
|
||||||
{'body': msg.get('body', {}), 'claim_id': None,
|
{'body': msg.get('body', {}), 'claim_id': None,
|
||||||
'ttl': msg['ttl'], 'claim_count': 0})
|
'ttl': msg['ttl'], 'claim_count': 0})
|
||||||
try:
|
utils._put_or_create_container(
|
||||||
self._client.put_object(
|
self._client,
|
||||||
utils._message_container(queue, project),
|
utils._message_container(queue, project),
|
||||||
slug,
|
slug,
|
||||||
contents=contents,
|
contents=contents,
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
headers={
|
headers={
|
||||||
'x-object-meta-clientid': str(client_uuid),
|
'x-object-meta-clientid': str(client_uuid),
|
||||||
'x-delete-after': msg['ttl']})
|
'x-delete-after': msg['ttl']})
|
||||||
except swiftclient.ClientException as exc:
|
|
||||||
# NOTE(flwang): To avoid check the queue existence each time when
|
|
||||||
# posting messages, let's catch the 404 and create the 'queue'
|
|
||||||
# on demand.
|
|
||||||
if exc.http_status == 404:
|
|
||||||
self._client.put_container(utils._message_container(queue,
|
|
||||||
project))
|
|
||||||
self._client.put_object(
|
|
||||||
utils._message_container(queue, project),
|
|
||||||
slug,
|
|
||||||
contents=contents,
|
|
||||||
content_type='application/json',
|
|
||||||
headers={
|
|
||||||
'x-object-meta-clientid': str(client_uuid),
|
|
||||||
'x-delete-after': msg['ttl']})
|
|
||||||
|
|
||||||
return slug
|
return slug
|
||||||
|
|
||||||
def delete(self, queue, message_id, project=None, claim=None):
|
def delete(self, queue, message_id, project=None, claim=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user