Skip to content

Commit

Permalink
refactor to get rid of persistent queues and change to singular lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Nov 13, 2024
1 parent f08180b commit 06e5f2b
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(self):
Start a specific queue - must pass input_queue_name.
"""
self.sqs_lock = Lock()
self.sqs = self.get_sqs()

@staticmethod
def get_queue_prefix():
Expand Down Expand Up @@ -82,7 +81,7 @@ def create_queue(self, queue_name: str) -> boto3.resources.base.ServiceResource:
# Optionally enable content-based deduplication for FIFO queues
attributes['ContentBasedDeduplication'] = 'true'
# Include other FIFO-specific attributes as needed
return self.sqs.create_queue(
return self.get_sqs().create_queue(
QueueName=queue_name,
Attributes=attributes
)
Expand All @@ -92,14 +91,7 @@ def get_or_create_queues(self, queue_name: str) -> List[boto3.resources.base.Ser
Initialize all queues for the given worker - try to create them if they are not found by name for whatever reason
"""
try:
found_queues = [q for q in self.sqs.queues.filter(QueueNamePrefix=queue_name)]
exact_match_queues = [queue for queue in found_queues if queue.attributes['QueueArn'].split(':')[-1] == queue_name]
logger.info(f"found queues are {found_queues}")
logger.info(f"exact queues are {exact_match_queues}")
if exact_match_queues:
return exact_match_queues
else:
return [self.create_queue(queue_name)]
return [self.get_sqs().get_queue_by_name(QueueName=queue_name)]
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "AWS.SimpleQueueService.NonExistentQueue":
return [self.create_queue(queue_name)]
Expand Down

0 comments on commit 06e5f2b

Please sign in to comment.