Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- 9324:9324
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Install system dependencies
run: sudo apt update && sudo apt install --no-install-recommends -y make git
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.11.6
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.12.0
rev: v1.15.0
hooks:
- id: mypy
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
9 changes: 6 additions & 3 deletions sqsx/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ def consume_messages(
wait_seconds: int = 10,
polling_wait_seconds: int = 10,
run_forever: bool = True,
enable_signal_to_exit_gracefully: bool = True,
) -> None:
logger.info(f"Starting consuming tasks, queue_url={self.url}")
signal.signal(signal.SIGINT, self._exit_gracefully)
signal.signal(signal.SIGTERM, self._exit_gracefully)

if enable_signal_to_exit_gracefully:
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)

while True:
if self._should_consume_tasks_stop:
Expand Down Expand Up @@ -63,7 +66,7 @@ def consume_messages(
if not run_forever:
break

def _exit_gracefully(self, signal_num, current_stack_frame) -> None:
def exit_gracefully(self, signal_num, current_stack_frame) -> None:
logger.info("Starting graceful shutdown process")
self._should_consume_tasks_stop = True

Expand Down
8 changes: 6 additions & 2 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ 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, polling_wait_seconds=0, run_forever=True)
queue.consume_messages(
wait_seconds=1, polling_wait_seconds=0, run_forever=True, enable_signal_to_exit_gracefully=True
)

assert handler.result_sum == 6

Expand Down Expand Up @@ -291,6 +293,8 @@ 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, polling_wait_seconds=0, run_forever=True)
raw_queue.consume_messages(
wait_seconds=1, polling_wait_seconds=0, run_forever=True, enable_signal_to_exit_gracefully=True
)

assert handler.call_count == 3