Enhance dashboard published feeds controls

This commit is contained in:
Abel Luck 2026-03-31 12:54:21 +02:00
parent e796e09d14
commit ca3d34053f
5 changed files with 177 additions and 29 deletions

View file

@ -503,6 +503,7 @@ def status_badge(*, label: str, tone: str) -> Renderable:
tones = {
"running": "bg-emerald-100 text-emerald-800",
"scheduled": "bg-sky-100 text-sky-800",
"queued": "bg-amber-200 text-amber-950",
"idle": "bg-slate-200 text-slate-700",
"failed": "bg-rose-100 text-rose-800",
"done": "bg-emerald-100 text-emerald-800",

View file

@ -799,8 +799,19 @@ def load_dashboard_view(
reference_time = now or datetime.now(UTC)
runs_view = load_runs_view(log_dir=log_dir, now=reference_time)
output_dir = Path(log_dir).parent
running_by_job_id = {
int(cast(int, execution["job_id"])): execution
for execution in runs_view["running"]
}
queued_by_job_id = {
int(cast(int, execution["job_id"])): execution
for execution in runs_view["queued"]
}
upcoming_by_job_id = {
int(cast(int, job["job_id"])): job for job in runs_view["upcoming"]
}
with database.connection_context():
sources = tuple(Source.select().order_by(Source.name.asc()))
jobs = tuple(Job.select(Job, Source).join(Source).order_by(Source.name.asc()))
failed_last_day = (
JobExecution.select()
.where(
@ -818,8 +829,15 @@ def load_dashboard_view(
"running": runs_view["running"],
"queued": runs_view["queued"],
"source_feeds": tuple(
_project_source_feed(source, output_dir, reference_time)
for source in sources
_project_source_feed(
cast(Job, job),
output_dir,
reference_time,
running_execution=running_by_job_id.get(_job_id(cast(Job, job))),
queued_execution=queued_by_job_id.get(_job_id(cast(Job, job))),
upcoming_job=upcoming_by_job_id.get(_job_id(cast(Job, job))),
)
for job in jobs
),
"snapshot": {
"running_now": str(len(runs_view["running"])),
@ -1076,8 +1094,15 @@ def _project_completed_execution(
def _project_source_feed(
source: Source, output_dir: Path, reference_time: datetime
job: Job,
output_dir: Path,
reference_time: datetime,
*,
running_execution: dict[str, object] | None = None,
queued_execution: dict[str, object] | None = None,
upcoming_job: dict[str, object] | None = None,
) -> dict[str, object]:
source = cast(Source, job.source)
source_slug = str(source.slug)
source_dir = feed_output_dir(out_dir=output_dir, feed_slug=source_slug)
feed_path = feed_output_path(out_dir=output_dir, feed_slug=source_slug)
@ -1087,12 +1112,22 @@ def _project_source_feed(
if feed_exists
else None
)
if running_execution is not None:
feed_status_label = str(running_execution["status"])
feed_status_tone = "scheduled"
elif queued_execution is not None:
feed_status_label = "Queued"
feed_status_tone = "queued"
else:
feed_status_label = "Available" if feed_exists else "Missing"
feed_status_tone = "done" if feed_exists else "failed"
return {
"source": source.name,
"slug": source_slug,
"feed_href": f"/feeds/{source_slug}/feed.rss",
"feed_status_label": "Available" if feed_exists else "Missing",
"feed_status_tone": "done" if feed_exists else "failed",
"feed_status_label": feed_status_label,
"feed_status_tone": feed_status_tone,
"feed_exists": feed_exists,
"last_updated": (
_humanize_relative_time(reference_time, updated_at)
@ -1100,6 +1135,24 @@ def _project_source_feed(
else "Never published"
),
"last_updated_iso": updated_at.isoformat() if updated_at is not None else None,
"next_run": (
str(upcoming_job["next_run"])
if upcoming_job is not None
else "Not scheduled"
),
"next_run_at": (
cast(str | None, upcoming_job["next_run_at"])
if upcoming_job is not None
else None
),
"run_disabled": (
bool(upcoming_job["run_disabled"]) if upcoming_job is not None else False
),
"run_post_path": (
str(upcoming_job["run_post_path"])
if upcoming_job is not None
else f"/actions/jobs/{_job_id(job)}/run-now"
),
"artifact_footprint": _format_bytes(_directory_size(source_dir)),
}

View file

@ -1,11 +1,13 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import cast
import htpy as h
from htpy import Node, Renderable
from repub.components import (
action_button,
app_shell,
header_action_link,
inline_link,
@ -89,6 +91,19 @@ def _source_feed_row(source_feed: Mapping[str, object]) -> tuple[Node, ...]:
if last_updated_iso is not None
else h.p(class_="font-medium text-slate-900")[str(source_feed["last_updated"])]
)
next_run_iso = source_feed.get("next_run_at")
next_run = (
h.time(
{
"data-next-run-at": str(next_run_iso),
"title": str(next_run_iso),
},
datetime=str(next_run_iso),
class_="font-medium text-slate-900",
)[str(source_feed["next_run"])]
if next_run_iso is not None
else h.p(class_="font-medium text-slate-900")[str(source_feed["next_run"])]
)
return (
h.div[
h.div(class_="font-semibold text-slate-950")[str(source_feed["source"])],
@ -108,9 +123,15 @@ def _source_feed_row(source_feed: Mapping[str, object]) -> tuple[Node, ...]:
tone=str(source_feed["feed_status_tone"]),
),
last_updated,
next_run,
h.p(class_="font-medium text-slate-900")[
str(source_feed["artifact_footprint"])
],
action_button(
label="Run now",
disabled=bool(source_feed["run_disabled"]),
post_path=cast(str | None, source_feed.get("run_post_path")),
),
)
@ -122,7 +143,15 @@ def published_feeds_table(
eyebrow="Published feeds",
title="Published feeds",
empty_message="No feeds have been published yet.",
headers=("Source", "Feed URL", "Status", "Last updated", "Disk usage"),
headers=(
"Source",
"Feed URL",
"Status",
"Last updated",
"Next run",
"Disk usage",
"Actions",
),
rows=rows,
actions=muted_action_link(href="/sources", label="Manage sources"),
)

View file

@ -394,9 +394,6 @@
.min-w-32 {
min-width: calc(var(--spacing) * 32);
}
.min-w-56 {
min-width: calc(var(--spacing) * 56);
}
.min-w-64 {
min-width: calc(var(--spacing) * 64);
}
@ -406,9 +403,6 @@
.min-w-\[64rem\] {
min-width: 64rem;
}
.min-w-\[70rem\] {
min-width: 70rem;
}
.flex-1 {
flex: 1;
}
@ -741,15 +735,9 @@
.pr-5 {
padding-right: calc(var(--spacing) * 5);
}
.pr-6 {
padding-right: calc(var(--spacing) * 6);
}
.pl-3 {
padding-left: calc(var(--spacing) * 3);
}
.pl-4 {
padding-left: calc(var(--spacing) * 4);
}
.text-center {
text-align: center;
}
@ -955,11 +943,6 @@
padding-left: calc(var(--spacing) * 3);
}
}
.first\:pl-4 {
&:first-child {
padding-left: calc(var(--spacing) * 4);
}
}
.hover\:bg-amber-300 {
&:hover {
@media (hover: hover) {