"""Utility methods to work with the availability polling queue.""" from availability import config from availability.connectors import sqs from availability.constants import error def get_availability_queue(store_id=None): """Get service-specific SQS queue. Args: store_id (int): ID of the store. If none, then try to use one from environment variable (this should be the case in daemon). Returns: Queue: SQS queue. """ if store_id is None: store_id = config.STORE_ID if store_id is None: # Fallback to old queue. This will be removed probably. queue_name = config.SQS_QUEUE_STORE_AVAILABILITY else: queue_name = config.SQS_STORE_SPECIFIC_QUEUE.format(store_id=store_id) sqs_queue = sqs.get_queue(queue_name) if not sqs_queue: raise ValueError(error.ERROR_MESSAGE_NO_SQS_QUEUE) sqs_queue.set_attributes( Attributes={ 'VisibilityTimeout': str( config.SQS_MESSAGE_VISIBILITY_TIMEOUT_SECONDS) } ) return sqs_queue