From f6d96df2c3aecb51ca97426efddb101dce6350d7 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 30 Oct 2026 13:24:53 +0100 Subject: feat(sender): add persistent retry backoff Persist retry state per source revision so temporary delivery failures survive worker restarts and duplicate queued tasks cannot bypass the retry schedule. Use capped exponential backoff, stop after a configurable attempt limit, and reset the retry budget when a source changes or an admin resends manually. --- tests/tasks/test_scanner.py | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/tasks/test_scanner.py') diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py index 3d138ac..6ace77f 100644 --- a/tests/tasks/test_scanner.py +++ b/tests/tasks/test_scanner.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: BSD-3-Clause +from datetime import UTC, datetime, timedelta from pathlib import Path from types import ModuleType from typing import Any @@ -1552,6 +1553,56 @@ def test_pending_webmention_is_requeued_on_next_scan( assert queued == [identifier] + +def test_temporary_failure_waits_until_retry_deadline_and_revision_resets_budget( + app: Flask, scanner_module: ModuleType, tmp_path: Path, monkeypatch: MonkeyPatch +) -> None: + configure_scanner(app, tmp_path) + path = write_post(tmp_path, "example", 'A') + queued: list[UUID] = [] + monkeypatch.setattr(scanner_module, "send_webmention", queued.append) + + run_scan(app, scanner_module) + assert len(queued) == 1 + identifier = queued.pop() + + with app.app_context(): + webmention = db.session.get(SentWebmention, identifier) + assert webmention is not None + webmention.attempt_count = 2 + webmention.next_retry_at = datetime.now(UTC) + timedelta(hours=4) + db.session.commit() + + run_scan(app, scanner_module) + assert queued == [] + + with app.app_context(): + webmention = db.session.get(SentWebmention, identifier) + assert webmention is not None + webmention.next_retry_at = datetime.now(UTC) - timedelta(seconds=1) + db.session.commit() + + run_scan(app, scanner_module) + assert queued == [identifier] + queued.clear() + + # Changing the h-entry creates a new desired revision with a fresh budget. + path.write_text(path.read_text().replace('>A', '>A updated')) + with app.app_context(): + webmention = db.session.get(SentWebmention, identifier) + assert webmention is not None + webmention.next_retry_at = datetime.now(UTC) + timedelta(days=2) + db.session.commit() + + run_scan(app, scanner_module) + assert queued == [identifier] + with app.app_context(): + webmention = db.session.get(SentWebmention, identifier) + assert webmention is not None + assert webmention.desired_revision == 2 + assert webmention.attempt_count == 0 + assert webmention.next_retry_at is None + def test_invalid_known_source_is_not_deleted( app: Flask, scanner_module: ModuleType, -- cgit v1.3.1