From 990210f9308025b6797363ee2eb05beeaf7f6802 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Wed, 6 Sep 2017 16:36:24 +0200 Subject: [PATCH] Reduce duplication in swift post messages It uses the utility to repost messages when container doesn't exist. Change-Id: I71399e3ff077f447645dd01a47c920a0e82fe326 --- zaqar/storage/swift/messages.py | 34 +++++++++------------------------ 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/zaqar/storage/swift/messages.py b/zaqar/storage/swift/messages.py index f6aba9004..e26e7afd1 100644 --- a/zaqar/storage/swift/messages.py +++ b/zaqar/storage/swift/messages.py @@ -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):