Private
Public Access
scripts/upgrade.sh now fetches tags and does a detached-HEAD checkout of the latest one (git tag --sort=-creatordate | head -n1), matching the ds-chat project's deploy/upgrade.sh exactly rather than a plain git pull on whatever branch happened to be checked out. Errors clearly if the repo has no tags yet (true for Evection right now — nothing to deploy until a release is tagged and pushed), and no-ops cleanly if already on the latest tag. scripts/install.sh does the same tag pin on first install (falling back to whatever's checked out if no tags exist yet), so the very first deploy is consistent with every upgrade after it. Added a GET /health/ endpoint (apps.core.views.health) that checks DB connectivity and is exempt from the first-run setup redirect, for the upgrade script's post-restart verification (curled over the gunicorn unix socket, same as ds-chat's curl-based check) and for any external uptime monitor. While wiring the setup-wizard exemption for /health/, found that SetupWizardMiddleware._a_user_exists's reset fixture was scoped only to apps/accounts/tests.py, so a test anywhere else that creates a user and makes a request could leak a stale "a user exists" into later test files with no reset — confirmed this concretely by temporarily breaking the new exemption and watching the "works before setup" test still pass purely from accounts/tests.py leaving the module-order-adjacent apps/articles tests to poison the shared class attribute. Moved the fixture to a new top-level conftest.py so it's autouse across every test file, which also makes the new health-check test meaningful regardless of run order. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
from django.contrib import messages
|
|
from django.contrib.auth.decorators import user_passes_test
|
|
from django.db import connection
|
|
from django.db.models import Count, Q
|
|
from django.http import JsonResponse
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
from django.views.decorators.http import require_POST
|
|
|
|
from apps.articles.models import Article
|
|
from apps.feeds.models import Feed, Subscription
|
|
from apps.feeds.tasks import fetch_feed, reset_feed_backoff
|
|
|
|
is_admin = user_passes_test(lambda u: u.is_authenticated and u.is_staff)
|
|
|
|
|
|
def health(request):
|
|
"""Unauthenticated liveness/readiness check — reachable even before
|
|
first-run setup (see SetupWizardMiddleware). Used by scripts/upgrade.sh
|
|
to confirm a freshly restarted deploy actually came up, and is a
|
|
reasonable target for any external uptime monitor too."""
|
|
try:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute("SELECT 1")
|
|
except Exception:
|
|
return JsonResponse({"status": "error"}, status=503)
|
|
return JsonResponse({"status": "ok"})
|
|
|
|
|
|
@is_admin
|
|
def dashboard(request):
|
|
feeds = Feed.objects.annotate(subscriber_count=Count("subscriptions"))
|
|
erroring_feeds = feeds.filter(
|
|
Q(last_fetch_status=Feed.STATUS_ERROR) | Q(fetch_error_count__gt=0)
|
|
).order_by("-fetch_error_count")
|
|
|
|
stats = {
|
|
"feed_count": feeds.count(),
|
|
"active_feed_count": feeds.filter(is_active=True).count(),
|
|
"error_feed_count": erroring_feeds.count(),
|
|
"subscription_count": Subscription.objects.count(),
|
|
"article_count": Article.objects.count(),
|
|
}
|
|
|
|
return render(
|
|
request,
|
|
"core/dashboard.html",
|
|
{"stats": stats, "erroring_feeds": erroring_feeds},
|
|
)
|
|
|
|
|
|
@is_admin
|
|
@require_POST
|
|
def retry_feed(request, feed_id):
|
|
feed = get_object_or_404(Feed, pk=feed_id)
|
|
reset_feed_backoff.delay(feed.id)
|
|
fetch_feed.delay(feed.id)
|
|
messages.success(request, f"Queued an immediate retry for '{feed.title or feed.feed_url}'.")
|
|
return redirect("core:dashboard")
|