Skip to content

Commit d96c688

Browse files
Merge pull request #100 from Doist/brandon/hotfix
fix: re-add change_visibility to toy memory impl (hotfix)
2 parents 25f74c7 + 446964a commit d96c688

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sqs_workers/memory_sqs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
Ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html
1717
"""
1818
import datetime
19+
import logging
1920
import uuid
2021
from typing import Any, Dict, List
2122

2223
import attr
2324

25+
logger = logging.getLogger(__name__)
26+
2427

2528
@attr.s
2629
class MemoryAWS:
@@ -269,3 +272,15 @@ def from_kwargs(cls, queue_impl, kwargs):
269272
return MemoryMessage(
270273
queue_impl, body, message_atttributes, attributes, execute_at
271274
)
275+
276+
def change_visibility(self, VisibilityTimeout="0", **kwargs):
277+
if self.message_id in self.queue_impl.in_flight:
278+
now = datetime.datetime.utcnow()
279+
sec = int(VisibilityTimeout)
280+
execute_at = now + datetime.timedelta(seconds=sec)
281+
updated_message = attr.evolve(self, execute_at=execute_at)
282+
updated_message.attributes["ApproximateReceiveCount"] += 1
283+
self.queue_impl.messages.append(updated_message)
284+
self.queue_impl.in_flight.pop(self.message_id)
285+
else:
286+
logger.warning("Tried to change visibility of message not in flight")

0 commit comments

Comments
 (0)