aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/models
diff options
context:
space:
mode:
authorDennis Fink2026-11-19 19:42:41 +0100
committerDennis Fink2026-11-19 20:59:24 +0100
commit88f54d9a7699944b7d56f978e724b1c0b54dde98 (patch)
tree88ecc527903a91a6f6622ca288b278e5875aff3d /webmentions_ssg/models
parent8ec35babe87ff8139ec23cc10b858b7481f132db (diff)
downloadwebmentions-ssg-88f54d9a7699944b7d56f978e724b1c0b54dde98.tar.gz
webmentions-ssg-88f54d9a7699944b7d56f978e724b1c0b54dde98.zip
feat(sender): add bulk resend and delivery history
Allow admins to resend all failed Webmentions globally or requeue every delivery for a source using the shared confirmation workflow. Record outgoing status history, expand sent source details, and provide human-readable guidance for current and historical delivery failures.
Diffstat (limited to 'webmentions_ssg/models')
-rw-r--r--webmentions_ssg/models/sources.py60
1 files changed, 59 insertions, 1 deletions
diff --git a/webmentions_ssg/models/sources.py b/webmentions_ssg/models/sources.py
index be56e24..9fc4212 100644
--- a/webmentions_ssg/models/sources.py
+++ b/webmentions_ssg/models/sources.py
@@ -5,7 +5,7 @@
"""Source documents and outgoing Webmention state."""
from collections.abc import Collection
-from datetime import datetime
+from datetime import UTC, datetime
from enum import StrEnum
from uuid import UUID, uuid7
@@ -15,6 +15,7 @@ from sqlalchemy import (
DateTime,
Enum,
ForeignKey,
+ Index,
Integer,
String,
Text,
@@ -182,6 +183,23 @@ class SentWebmention(Base):
)
source: Mapped[SourceDocument] = relationship(back_populates="sent_webmentions")
+ status_events: Mapped[list[SentWebmentionStatusEvent]] = relationship(
+ back_populates="webmention", cascade="all, delete-orphan"
+ )
+
+ def record_status_event(self, action: str, *, at: datetime | None = None) -> None:
+ """Save a snapshot of this mention's current delivery state."""
+ self.status_events.append(
+ SentWebmentionStatusEvent(
+ status=self.status,
+ action=action,
+ revision=self.desired_revision,
+ attempt_count=self.attempt_count,
+ failure_reason=self.failure_reason,
+ endpoint_response_status=self.endpoint_response_status,
+ occurred_at=at or datetime.now(UTC),
+ )
+ )
__table_args__ = (
UniqueConstraint(
@@ -243,3 +261,43 @@ class SentWebmention(Base):
def created_at(self) -> datetime:
"""Return the creation time encoded in the Webmention UUID."""
return uuid7_to_datetime(self.uuid)
+
+
+class SentWebmentionStatusEvent(Base):
+ """Persist delivery outcomes and manual requeues for an outgoing Webmention."""
+
+ __tablename__ = "sent_webmention_status_events"
+
+ id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
+ webmention_uuid: Mapped[UUID] = mapped_column(
+ Uuid(as_uuid=True),
+ ForeignKey("sent_webmentions.uuid", ondelete="CASCADE"),
+ nullable=False,
+ )
+ status: Mapped[SentWebmentionStatus | None] = mapped_column(
+ Enum(
+ SentWebmentionStatus,
+ name="sent_webmention_status",
+ values_callable=lambda enum_type: [member.value for member in enum_type],
+ native_enum=False,
+ ),
+ nullable=True,
+ )
+ action: Mapped[str] = mapped_column(String(80), nullable=False)
+ revision: Mapped[int] = mapped_column(Integer(), nullable=False)
+ attempt_count: Mapped[int] = mapped_column(Integer(), nullable=False)
+ failure_reason: Mapped[str | None] = mapped_column(Text(), nullable=True)
+ endpoint_response_status: Mapped[int | None] = mapped_column(
+ Integer(), nullable=True
+ )
+ occurred_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), nullable=False
+ )
+
+ webmention: Mapped[SentWebmention] = relationship(back_populates="status_events")
+
+ __table_args__ = (
+ Index(
+ "ix_sent_webmention_status_events_webmention_id", "webmention_uuid", "id"
+ ),
+ )