Reduce duplication in swift post messages

It uses the utility to repost messages when container doesn't exist.

Change-Id: I71399e3ff077f447645dd01a47c920a0e82fe326
This commit is contained in:
Thomas Herve 2017-09-06 16:36:24 +02:00
parent b2d9b90499
commit 990210f930

View File

@ -214,31 +214,15 @@ class MessageController(storage.Message):
contents = jsonutils.dumps(
{'body': msg.get('body', {}), 'claim_id': None,
'ttl': msg['ttl'], 'claim_count': 0})
try:
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']})
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']})
utils._put_or_create_container(
self._client,
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
def delete(self, queue, message_id, project=None, claim=None):