Skip to content

Commit

Permalink
Minor improvements on SQSProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeyk committed Jan 8, 2017
1 parent 5a537bb commit ce49da5
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions loafer/ext/aws/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ def __init__(self, source, endpoint_url=None, use_ssl=True, options=None, loop=N
self.endpoint_url = endpoint_url
self.use_ssl = use_ssl
self._loop = loop or asyncio.get_event_loop()
self._client = None
self._options = options
self._options = options or {}

@cached_property
def client(self):
if not self._client:
session = aiobotocore.get_session(loop=self._loop)
self._client = session.create_client('sqs', endpoint_url=self.endpoint_url,
use_ssl=self.use_ssl)
return self._client
session = aiobotocore.get_session(loop=self._loop)
return session.create_client('sqs', endpoint_url=self.endpoint_url,
use_ssl=self.use_ssl)

async def get_queue_url(self):
response = await self.client.get_queue_url(QueueName=self.source)
Expand All @@ -45,9 +42,8 @@ async def fetch_messages(self):
queue_url = await self.get_queue_url()
logger.debug('fetching messages on {}'.format(queue_url))

options = self._options or {}
try:
response = await self.client.receive_message(QueueUrl=queue_url, **options)
response = await self.client.receive_message(QueueUrl=queue_url, **self._options)
except botocore.exceptions.ClientError as exc:
raise ProviderError('Error when fetching messages') from exc

Expand Down

0 comments on commit ce49da5

Please sign in to comment.