refinements and fixes

This commit is contained in:
holger krekel 2024-04-03 18:50:20 +02:00
parent cc4920ddc7
commit 9b76d46558
2 changed files with 7 additions and 2 deletions

View File

@ -50,6 +50,7 @@ class PersistentQueueItem:
@classmethod
def create(cls, queue_dir, addr, start_ts, token):
queue_id = uuid4().hex
start_ts = int(start_ts)
path = queue_dir.joinpath(queue_id)
tmp_path = path.with_name(path.name + ".tmp")
tmp_path.write_text(f"{addr}\n{start_ts}\n{token}")
@ -61,6 +62,9 @@ class PersistentQueueItem:
addr, start_ts, token = path.read_text().split("\n", maxsplit=2)
return cls(path, addr, int(start_ts), token)
def __lt__(self, other):
return self.start_ts < other.start_ts
class Notifier:
URL = "https://notifications.delta.chat/notify"
@ -95,7 +99,7 @@ class Notifier:
def queue_for_retry(self, queue_item, retry_num=0):
delay = self.compute_delay(retry_num)
when = time.time() + delay
when = int(time.time()) + delay
deadline = queue_item.start_ts + self.DROP_DEADLINE
if retry_num >= len(self.retry_queues) or when > deadline:
queue_item.delete()

View File

@ -238,7 +238,7 @@ def test_requeue_removes_tmp_files(notifier, metadata, testaddr, caplog):
assert not p.exists()
assert notifier2.retry_queues[0].qsize() == 1
when, queue_item = notifier2.retry_queues[0].get()
assert when >= int(time.time())
assert when <= int(time.time())
assert queue_item.addr == testaddr
@ -295,3 +295,4 @@ def test_persistent_queue_items(tmp_path, testaddr, token):
assert item2 == queue_item
item2.delete()
assert not item2.path.exists()
assert not queue_item < item2 and not item2 < queue_item