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

Added threading feature. #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Changes for alignment with PEP-8 standards
gautamkhanapuri committed Oct 13, 2024
commit 03e76ce54b3fec49fe9699db9159bf5c0f0fdece
17 changes: 9 additions & 8 deletions aws_sqs_consumer/consumer.py
Original file line number Diff line number Diff line change
@@ -31,9 +31,9 @@ def __init__(
wait_time_seconds=1,
visibility_timeout_seconds=None,
polling_wait_time_ms=0,
daemon: bool=True,
thread_name: str="consumer",
threaded: bool=True
daemon: bool = True,
thread_name: str = "consumer",
threaded: bool = True
):
self.queue_url = queue_url
self.attribute_names = attribute_names
@@ -147,14 +147,17 @@ def stop(self):

def start_consumer(self):
"""
Starts the process of receiving sqs messages either in main thread (if threaded=False) or
separate thread (if threaded=True) depending on threaded
Starts the process of receiving sqs messages either in main
thread (if threaded=False) or separate thread (if threaded=True)
depending on threaded.
"""
if not self.threaded:
self.start()
else:
thread_name = self.thread_name_prefix + str(uuid4())
self._sqs_thread = threading.Thread(target=self.start, name=thread_name, daemon=self.daemon)
self._sqs_thread = threading.Thread(target=self.start,
name=thread_name,
daemon=self.daemon)
self._sqs_thread.start()

def _process_message(self, message: Message):
@@ -215,5 +218,3 @@ def _sqs_client_params(self):

def _polling_wait(self):
time.sleep(self.polling_wait_time_ms / 1000)