|
15 | 15 |
|
16 | 16 | Ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html
|
17 | 17 | """
|
18 |
| -import datetime |
19 | 18 | import logging
|
20 | 19 | import uuid
|
| 20 | +from datetime import datetime, timedelta, timezone |
21 | 21 | from typing import Any, Dict, List
|
22 | 22 |
|
23 | 23 | import attr
|
@@ -141,8 +141,8 @@ def receive_messages(self, WaitTimeSeconds="0", MaxNumberOfMessages="10", **kwar
|
141 | 141 | ready_messages = []
|
142 | 142 | push_back_messages = []
|
143 | 143 |
|
144 |
| - now = datetime.datetime.now(tz=datetime.UTC) |
145 |
| - threshold = now + datetime.timedelta(seconds=wait_seconds) |
| 144 | + now = datetime.now(tz=timezone.utc) |
| 145 | + threshold = now + timedelta(seconds=wait_seconds) |
146 | 146 |
|
147 | 147 | # before retrieving messages, go through in_flight and return any
|
148 | 148 | # messages whose "invisible" timeout has expired back to the pool
|
@@ -197,14 +197,14 @@ def change_message_visibility_batch(self, Entries):
|
197 | 197 | found_entries = []
|
198 | 198 | not_found_entries = []
|
199 | 199 |
|
200 |
| - now = datetime.datetime.now(tz=datetime.UTC) |
| 200 | + now = datetime.now(tz=timezone.utc) |
201 | 201 |
|
202 | 202 | for e in Entries:
|
203 | 203 | if e["Id"] in self.in_flight:
|
204 | 204 | found_entries.append(e)
|
205 | 205 | in_flight_message = self.in_flight[e["Id"]]
|
206 | 206 | sec = int(e["VisibilityTimeout"])
|
207 |
| - visible_at = now + datetime.timedelta(seconds=sec) |
| 207 | + visible_at = now + timedelta(seconds=sec) |
208 | 208 | updated_message = attr.evolve(in_flight_message, visible_at=visible_at)
|
209 | 209 | self.in_flight[e["Id"]] = updated_message
|
210 | 210 | else:
|
@@ -247,9 +247,7 @@ class MemoryMessage:
|
247 | 247 | attributes: Dict[str, Any] = attr.ib(factory=dict)
|
248 | 248 |
|
249 | 249 | # Internal attribute which contains the execution time.
|
250 |
| - visible_at: datetime.datetime = attr.ib( |
251 |
| - factory=lambda: datetime.datetime.now(tz=datetime.UTC) |
252 |
| - ) |
| 250 | + visible_at: datetime = attr.ib(factory=lambda: datetime.now(tz=timezone.utc)) |
253 | 251 |
|
254 | 252 | # A unique identifier for the message
|
255 | 253 | message_id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
@@ -277,20 +275,20 @@ def from_kwargs(cls, queue_impl, kwargs):
|
277 | 275 | if "MessageGroupId" in kwargs:
|
278 | 276 | attributes["MessageGroupId"] = kwargs["MessageGroupId"]
|
279 | 277 |
|
280 |
| - visible_at = datetime.datetime.now(tz=datetime.UTC) |
| 278 | + visible_at = datetime.now(tz=timezone.utc) |
281 | 279 | if "DelaySeconds" in kwargs:
|
282 | 280 | delay_seconds_int = int(kwargs["DelaySeconds"])
|
283 |
| - visible_at += datetime.timedelta(seconds=delay_seconds_int) |
| 281 | + visible_at += timedelta(seconds=delay_seconds_int) |
284 | 282 |
|
285 | 283 | return MemoryMessage(
|
286 | 284 | queue_impl, body, message_atttributes, attributes, visible_at
|
287 | 285 | )
|
288 | 286 |
|
289 | 287 | def change_visibility(self, VisibilityTimeout="0", **kwargs):
|
290 | 288 | if self.message_id in self.queue_impl.in_flight:
|
291 |
| - now = datetime.datetime.now(tz=datetime.UTC) |
| 289 | + now = datetime.now(tz=timezone.utc) |
292 | 290 | sec = int(VisibilityTimeout)
|
293 |
| - visible_at = now + datetime.timedelta(seconds=sec) |
| 291 | + visible_at = now + timedelta(seconds=sec) |
294 | 292 | updated_message = attr.evolve(self, visible_at=visible_at)
|
295 | 293 | self.queue_impl.in_flight[self.message_id] = updated_message
|
296 | 294 | else:
|
|
0 commit comments