Skip to content

Commit

Permalink
Merge pull request #100 from Doist/brandon/hotfix
Browse files Browse the repository at this point in the history
fix: re-add change_visibility to toy memory impl (hotfix)
  • Loading branch information
brandon-doist authored Jul 31, 2024
2 parents 25f74c7 + 446964a commit d96c688
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sqs_workers/memory_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
Ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html
"""
import datetime
import logging
import uuid
from typing import Any, Dict, List

import attr

logger = logging.getLogger(__name__)


@attr.s
class MemoryAWS:
Expand Down Expand Up @@ -269,3 +272,15 @@ def from_kwargs(cls, queue_impl, kwargs):
return MemoryMessage(
queue_impl, body, message_atttributes, attributes, execute_at
)

def change_visibility(self, VisibilityTimeout="0", **kwargs):
if self.message_id in self.queue_impl.in_flight:
now = datetime.datetime.utcnow()
sec = int(VisibilityTimeout)
execute_at = now + datetime.timedelta(seconds=sec)
updated_message = attr.evolve(self, execute_at=execute_at)
updated_message.attributes["ApproximateReceiveCount"] += 1
self.queue_impl.messages.append(updated_message)
self.queue_impl.in_flight.pop(self.message_id)
else:
logger.warning("Tried to change visibility of message not in flight")

0 comments on commit d96c688

Please sign in to comment.