mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-09 00:18:13 +08:00
Fix 'receive_message_wait_time_seconds' SQS broker management (#243)
* Fix 'receive_message_wait_time_seconds' SQS broker management * Remove socket volume from localstack container
This commit is contained in:
@@ -7,6 +7,10 @@ ENV PYTHONUNBUFFERED 1
|
|||||||
# Sets the default shell to bash
|
# Sets the default shell to bash
|
||||||
ENV SHELL /bin/bash
|
ENV SHELL /bin/bash
|
||||||
|
|
||||||
|
RUN set -ex \
|
||||||
|
&& apt update \
|
||||||
|
&& apt-get install gcc python3-dev --yes
|
||||||
|
|
||||||
# Upgrades pip
|
# Upgrades pip
|
||||||
RUN pip install -U pip setuptools
|
RUN pip install -U pip setuptools
|
||||||
|
|
||||||
|
|||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Note that this file needs to have the executable bit set for it to work with later localstack implementations.
|
||||||
|
|
||||||
|
export DEFAULT_REGION=us-west-2
|
||||||
|
|
||||||
|
create_sqs() {
|
||||||
|
QUEUE_NAME="$1"
|
||||||
|
TIMEOUT=${2:-60}
|
||||||
|
DL_QUEUE_URL=$(awslocal sqs create-queue --queue-name "dl-$QUEUE_NAME" --query QueueUrl --output text)
|
||||||
|
echo ">>> Created $DL_QUEUE_URL queue!"
|
||||||
|
DL_QUEUE_ARN=$(awslocal sqs get-queue-attributes --queue-url "$DL_QUEUE_URL" --attribute-names QueueArn --query Attributes.QueueArn --output text)
|
||||||
|
awslocal sqs create-queue --queue-name "$QUEUE_NAME" --attributes '{
|
||||||
|
"RedrivePolicy": "{\"deadLetterTargetArn\": \"'"$DL_QUEUE_ARN"'\",\"maxReceiveCount\":\"3\"}",
|
||||||
|
"VisibilityTimeout": "'"$TIMEOUT"'"
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create SQS queues
|
||||||
|
create_sqs testing
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import copy
|
||||||
|
|
||||||
from boto3 import Session
|
from boto3 import Session
|
||||||
from botocore.client import ClientError
|
from botocore.client import ClientError
|
||||||
|
|
||||||
@@ -78,15 +80,15 @@ class Sqs(Broker):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_connection(list_key: str = None) -> Session:
|
def get_connection(list_key: str = None) -> Session:
|
||||||
config = Conf.SQS
|
config_cloned = copy.deepcopy(Conf.SQS)
|
||||||
if "aws_region" in config:
|
if "aws_region" in config_cloned:
|
||||||
config["region_name"] = config["aws_region"]
|
config_cloned["region_name"] = config_cloned["aws_region"]
|
||||||
del config["aws_region"]
|
del config_cloned["aws_region"]
|
||||||
|
|
||||||
if "receive_message_wait_time_seconds" in config:
|
if "receive_message_wait_time_seconds" in config_cloned:
|
||||||
del config["receive_message_wait_time_seconds"]
|
del config_cloned["receive_message_wait_time_seconds"]
|
||||||
|
|
||||||
return Session(**config)
|
return Session(**config_cloned)
|
||||||
|
|
||||||
def get_queue(self):
|
def get_queue(self):
|
||||||
self.sqs = self.connection.resource("sqs")
|
self.sqs = self.connection.resource("sqs")
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ def test_ironmq(monkeypatch):
|
|||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
not os.getenv("AWS_ACCESS_KEY_ID"), reason="requires AWS credentials"
|
not os.getenv("AWS_ACCESS_KEY_ID"), reason="requires AWS credentials"
|
||||||
)
|
)
|
||||||
def canceled_sqs(monkeypatch):
|
def test_sqs(monkeypatch):
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
Conf,
|
Conf,
|
||||||
"SQS",
|
"SQS",
|
||||||
@@ -132,11 +132,13 @@ def canceled_sqs(monkeypatch):
|
|||||||
"aws_region": os.getenv("AWS_REGION"),
|
"aws_region": os.getenv("AWS_REGION"),
|
||||||
"aws_access_key_id": os.getenv("AWS_ACCESS_KEY_ID"),
|
"aws_access_key_id": os.getenv("AWS_ACCESS_KEY_ID"),
|
||||||
"aws_secret_access_key": os.getenv("AWS_SECRET_ACCESS_KEY"),
|
"aws_secret_access_key": os.getenv("AWS_SECRET_ACCESS_KEY"),
|
||||||
"receive_message_wait_time_seconds": 20,
|
"receive_message_wait_time_seconds": 5,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# check broker
|
# check broker
|
||||||
broker = get_broker(list_key=uuid()[0])
|
broker = get_broker(list_key="testing")
|
||||||
|
assert "receive_message_wait_time_seconds" in Conf.SQS
|
||||||
|
assert "aws_region" in Conf.SQS
|
||||||
assert broker.ping() is True
|
assert broker.ping() is True
|
||||||
assert broker.info() is not None
|
assert broker.info() is not None
|
||||||
assert broker.queue_size() == 0
|
assert broker.queue_size() == 0
|
||||||
@@ -173,7 +175,7 @@ def canceled_sqs(monkeypatch):
|
|||||||
broker.enqueue("test")
|
broker.enqueue("test")
|
||||||
while task is None:
|
while task is None:
|
||||||
task = broker.dequeue()[0]
|
task = broker.dequeue()[0]
|
||||||
broker.fail(task[0])
|
broker.fail(task[0][0])
|
||||||
# bulk test
|
# bulk test
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
broker.enqueue("test")
|
broker.enqueue("test")
|
||||||
|
|||||||
@@ -13,15 +13,41 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
aws:
|
||||||
|
container_name: aws
|
||||||
|
image: localstack/localstack:3.4.0
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:4566:4566" # LocalStack Gateway
|
||||||
|
- "127.0.0.1:4510-4559:4510-4559" # External services port range
|
||||||
|
environment:
|
||||||
|
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-us-west-2}
|
||||||
|
DEFAULT_REGION: ${AWS_DEFAULT_REGION:-us-west-2}
|
||||||
|
SQS_ENDPOINT_STRATEGY: path
|
||||||
|
SERVICES: sqs
|
||||||
|
LOCALSTACK_HOST: aws
|
||||||
|
DEBUG: 1
|
||||||
|
LS_LOG: trace
|
||||||
|
volumes:
|
||||||
|
- ./containers/localstack:/etc/localstack/init/ready.d
|
||||||
|
networks:
|
||||||
|
- main
|
||||||
|
|
||||||
django-q2:
|
django-q2:
|
||||||
build:
|
build:
|
||||||
dockerfile: ./Dockerfile.dev
|
dockerfile: ./Dockerfile.dev
|
||||||
context: .
|
context: .
|
||||||
|
environment:
|
||||||
|
AWS_ENDPOINT_URL: http://aws:4566
|
||||||
|
AWS_REGION: ${AWS_REGION:-us-west-2}
|
||||||
|
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-test}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-test}
|
||||||
|
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-us-west-2}
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
- mongo
|
- mongo
|
||||||
|
- aws
|
||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user