Skip to content

Commit

Permalink
chore: other small refactoring from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-doist committed Jul 31, 2024
1 parent 36d0c3f commit f8965d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sqs_workers/memory_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,13 @@ def change_message_visibility_batch(self, Entries):
found_entries = []
not_found_entries = []

now = datetime.datetime.utcnow()

for e in Entries:
if e["Id"] in self.in_flight:
found_entries.append(e)
in_flight_message = self.in_flight[e["Id"]]
sec = int(e["VisibilityTimeout"])
now = datetime.datetime.utcnow()
execute_at = now + datetime.timedelta(seconds=sec)
updated_message = attr.evolve(in_flight_message, execute_at=execute_at)
updated_message.attributes["ApproximateReceiveCount"] += 1
Expand Down
7 changes: 6 additions & 1 deletion sqs_workers/sqs_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class SQSEnv:
queue_prefix = attr.ib(default="")
codec: str = attr.ib(default=codecs.DEFAULT_CONTENT_TYPE)

# retry settings for internal boto
retry_max_attempts: int = attr.ib(default=3)
retry_mode: str = attr.ib(default="standard")

# queue-specific settings
backoff_policy = attr.ib(default=DEFAULT_BACKOFF)

Expand All @@ -62,7 +66,8 @@ class SQSEnv:
def __attrs_post_init__(self):
self.context = self.context_maker()
# https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html
retry_config = Config(retries={"max_attempts": 3, "mode": "standard"})
retry_dict = {"max_attempts": self.retry_max_attempts, "mode": self.retry_mode}
retry_config = Config(retries=retry_dict)
if not self.sqs_client:
self.sqs_client = self.session.client("sqs", config=retry_config)
if not self.sqs_resource:
Expand Down

0 comments on commit f8965d4

Please sign in to comment.