Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5589 try locking mechanism #118

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/queue/queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from typing import List, Dict, Tuple
import os
from threading import Lock

import boto3
import botocore
Expand All @@ -17,6 +18,7 @@ def __init__(self):
"""
Start a specific queue - must pass input_queue_name.
"""
self.sqs_lock = Lock()
self.sqs = self.get_sqs()

@staticmethod
Expand Down Expand Up @@ -111,14 +113,16 @@ def get_sqs(self) -> boto3.resources.base.ServiceResource:
deploy_env = get_environment_setting("DEPLOY_ENV")
if deploy_env == "local":
logger.info(f"Using ElasticMQ Interface")
return boto3.resource('sqs',
region_name=(get_environment_setting("AWS_DEFAULT_REGION") or 'eu-central-1'),
endpoint_url=(get_environment_setting("ELASTICMQ_URI") or 'http://presto-elasticmq:9324'),
aws_access_key_id=(get_environment_setting("AWS_ACCESS_KEY_ID") or 'x'),
aws_secret_access_key=(get_environment_setting("AWS_SECRET_ACCESS_KEY") or 'x'))
with self.sqs_lock:
return boto3.resource('sqs',
region_name=(get_environment_setting("AWS_DEFAULT_REGION") or 'eu-central-1'),
endpoint_url=(get_environment_setting("ELASTICMQ_URI") or 'http://presto-elasticmq:9324'),
aws_access_key_id=(get_environment_setting("AWS_ACCESS_KEY_ID") or 'x'),
aws_secret_access_key=(get_environment_setting("AWS_SECRET_ACCESS_KEY") or 'x'))
else:
logger.info(f"Using SQS Interface")
return boto3.resource('sqs', region_name=get_environment_setting("AWS_DEFAULT_REGION"))
with self.sqs_lock:
return boto3.resource('sqs', region_name=get_environment_setting("AWS_DEFAULT_REGION"))

def group_deletions(self, messages_with_queues: List[Tuple[schemas.Message, boto3.resources.base.ServiceResource]]) -> Dict[boto3.resources.base.ServiceResource, List[schemas.Message]]:
"""
Expand Down
Loading