Skip to content

Commit

Permalink
feat: add polling_wait_seconds kwarg on consume_messages (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
allisson committed Apr 12, 2024
1 parent ed6e291 commit 78f1d9d
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 279 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-ast
- id: fix-byte-order-marker
Expand All @@ -18,7 +18,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.7
hooks:
- id: ruff
- id: ruff-format
594 changes: 322 additions & 272 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sqsx"
version = "0.3.1"
version = "0.5.0"
description = "A simple task processor for Amazon SQS"
authors = ["Allisson Azevedo"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="sqsx",
version="0.4.0",
version="0.5.0",
description="A simple task processor for Amazon SQS",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
8 changes: 7 additions & 1 deletion sqsx/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

class BaseQueueMixin:
def consume_messages(
self, max_messages: int = 1, max_threads: int = 1, wait_seconds: int = 10, run_forever: bool = True
self,
max_messages: int = 1,
max_threads: int = 1,
wait_seconds: int = 10,
polling_wait_seconds: int = 10,
run_forever: bool = True,
) -> None:
logger.info(f"Starting consuming tasks, queue_url={self.url}")
signal.signal(signal.SIGINT, self._exit_gracefully)
Expand All @@ -31,6 +36,7 @@ def consume_messages(
AttributeNames=["All"],
MaxNumberOfMessages=min(max_messages, 10),
MessageAttributeNames=["All"],
WaitTimeSeconds=polling_wait_seconds,
)

sqs_messages = response.get("Messages", [])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_queue_exit_gracefully(queue):
queue.add_task_handler("my_task", handler)
queue.add_task("my_task", a=1, b=2, c=3)

queue.consume_messages(wait_seconds=1, run_forever=True)
queue.consume_messages(wait_seconds=1, polling_wait_seconds=0, run_forever=True)

assert handler.result_sum == 6

Expand Down Expand Up @@ -291,6 +291,6 @@ def test_raw_queue_exit_gracefully(raw_queue):
raw_queue.add_message(message_body="Message Body")
raw_queue.add_message(message_body="Message Body")

raw_queue.consume_messages(wait_seconds=1, run_forever=True)
raw_queue.consume_messages(wait_seconds=1, polling_wait_seconds=0, run_forever=True)

assert handler.call_count == 3

0 comments on commit 78f1d9d

Please sign in to comment.