From b908ee61770dc78f8d8fbbbfc4f3c00d7877d42a Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Wed, 18 Nov 2026 08:01:26 +0100 Subject: feat(core): add dashboard overview Replace the root redirect with an authenticated dashboard showing received and outgoing status counts, recent activity, pending sends, retries, and queue depth. Persist the last completed source scan so operational status survives restarts and only advances after a successful, conclusive scan. --- .../2b4c6e8a0d12_last_completed_source_scan.py | 38 ++++++ webmentions_ssg/models/scan_state.py | 23 ++++ webmentions_ssg/tasks/scanner.py | 6 + webmentions_ssg/templates/base.html | 2 + webmentions_ssg/templates/dashboard.html | 148 +++++++++++++++++++++ webmentions_ssg/views/__init__.py | 3 +- webmentions_ssg/views/dashboard.py | 123 +++++++++++++++++ webmentions_ssg/views/session.py | 9 -- 8 files changed, 342 insertions(+), 10 deletions(-) create mode 100644 webmentions_ssg/migrations/versions/2b4c6e8a0d12_last_completed_source_scan.py create mode 100644 webmentions_ssg/models/scan_state.py create mode 100644 webmentions_ssg/templates/dashboard.html create mode 100644 webmentions_ssg/views/dashboard.py (limited to 'webmentions_ssg') diff --git a/webmentions_ssg/migrations/versions/2b4c6e8a0d12_last_completed_source_scan.py b/webmentions_ssg/migrations/versions/2b4c6e8a0d12_last_completed_source_scan.py new file mode 100644 index 0000000..168647f --- /dev/null +++ b/webmentions_ssg/migrations/versions/2b4c6e8a0d12_last_completed_source_scan.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Track the last successful source scan. + +Revision ID: 2b4c6e8a0d12 +Revises: ef8a9b6c2d41 +""" + +import sqlalchemy as sa +from alembic import op + +revision = "2b4c6e8a0d12" +down_revision = "ef8a9b6c2d41" +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table( + "scan_state", + sa.Column("id", sa.Integer(), primary_key=True), + sa.Column("last_completed_at", sa.DateTime(timezone=True), nullable=False), + ) + # Seed a best-effort historical completion time from previously scanned + # sources. The next completed scan will update the authoritative value. + op.execute( + sa.text( + "INSERT INTO scan_state (id, last_completed_at) " + "SELECT 1, MAX(last_seen_at) FROM source_documents " + "HAVING COUNT(*) > 0" + ) + ) + + +def downgrade(): + op.drop_table("scan_state") diff --git a/webmentions_ssg/models/scan_state.py b/webmentions_ssg/models/scan_state.py new file mode 100644 index 0000000..924c15d --- /dev/null +++ b/webmentions_ssg/models/scan_state.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Persist the last completed source scan for this single-site service.""" + +from datetime import datetime + +from sqlalchemy import DateTime, Integer +from sqlalchemy.orm import Mapped, mapped_column + +from ..extensions import Base + + +class ScanState(Base): + """The single row tracking the most recent successful source scan.""" + + __tablename__ = "scan_state" + + id: Mapped[int] = mapped_column(Integer, primary_key=True) + last_completed_at: Mapped[datetime] = mapped_column( + DateTime(timezone=True), nullable=False + ) diff --git a/webmentions_ssg/tasks/scanner.py b/webmentions_ssg/tasks/scanner.py index 1f98702..9058b9b 100644 --- a/webmentions_ssg/tasks/scanner.py +++ b/webmentions_ssg/tasks/scanner.py @@ -14,6 +14,7 @@ from huey.exceptions import RetryTask, TaskLockedException from sqlalchemy.orm import selectinload from ..extensions import db, huey +from ..models.scan_state import ScanState from ..models.sources import SentWebmention, SourceDocument from ..net import is_http_url from .sender import send_webmention @@ -304,6 +305,11 @@ def _scan_and_enqueue() -> None: db.session.commit() pending_count = enqueue_due_sends(scan_time) + # Mark a scan complete only after reconciliation and task enqueueing have + # succeeded. An inconclusive or interrupted scan keeps the previous value. + db.session.merge(ScanState(id=1, last_completed_at=datetime.now(UTC))) + db.session.commit() + current_app.logger.info( "Webmention source scan complete: %d sources scanned, " "%d missing sources, %d pending sends", diff --git a/webmentions_ssg/templates/base.html b/webmentions_ssg/templates/base.html index 4fffb38..115f193 100644 --- a/webmentions_ssg/templates/base.html +++ b/webmentions_ssg/templates/base.html @@ -43,6 +43,8 @@ SPDX-License-Identifier: BSD-3-Clause {% if current_user.is_authenticated %}