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

@ -719,7 +719,7 @@ def test_load_dashboard_view_lists_source_feed_artifacts(
app.config["REPUB_LOG_DIR"] = log_dir
log_dir.mkdir(parents=True)
create_source(
available_source = create_source(
name="Available source",
slug="available-source",
source_type="feed",
@ -733,7 +733,7 @@ def test_load_dashboard_view_lists_source_feed_artifacts(
cron_month="*",
feed_url="https://example.com/available.xml",
)
create_source(
missing_source = create_source(
name="Missing source",
slug="missing-source",
source_type="feed",
@ -757,6 +757,8 @@ def test_load_dashboard_view_lists_source_feed_artifacts(
updated_at = reference_time - timedelta(minutes=32)
updated_at_epoch = updated_at.timestamp()
os.utime(feed_path, (updated_at_epoch, updated_at_epoch))
available_job = Job.get(Job.source == available_source)
missing_job = Job.get(Job.source == missing_source)
source_feeds = cast(
tuple[dict[str, object], ...],
@ -773,6 +775,10 @@ def test_load_dashboard_view_lists_source_feed_artifacts(
"feed_exists": True,
"last_updated": "32 minutes ago",
"last_updated_iso": updated_at.isoformat(),
"next_run": "Not scheduled",
"next_run_at": None,
"run_disabled": False,
"run_post_path": f"/actions/jobs/{available_job.id}/run-now",
"artifact_footprint": "3.0 KB",
},
{
@ -784,11 +790,80 @@ def test_load_dashboard_view_lists_source_feed_artifacts(
"feed_exists": False,
"last_updated": "Never published",
"last_updated_iso": None,
"next_run": "Not scheduled",
"next_run_at": None,
"run_disabled": False,
"run_post_path": f"/actions/jobs/{missing_job.id}/run-now",
"artifact_footprint": "0 B",
},
)
def test_load_dashboard_view_projects_feed_status_from_job_runtime(
monkeypatch, tmp_path: Path
) -> None:
db_path = tmp_path / "dashboard-feed-status.db"
monkeypatch.setenv("REPUBLISHER_DB_PATH", str(db_path))
create_app()
log_dir = tmp_path / "out" / "logs"
log_dir.mkdir(parents=True)
reference_time = datetime(2026, 3, 30, 12, 30, tzinfo=UTC)
running_source = create_source(
name="Running source",
slug="running-source",
source_type="feed",
notes="",
spider_arguments="",
enabled=True,
cron_minute="35",
cron_hour="12",
cron_day_of_month="30",
cron_day_of_week="*",
cron_month="3",
feed_url="https://example.com/running.xml",
)
queued_source = create_source(
name="Queued source",
slug="queued-source",
source_type="feed",
notes="",
spider_arguments="",
enabled=True,
cron_minute="35",
cron_hour="12",
cron_day_of_month="30",
cron_day_of_week="*",
cron_month="3",
feed_url="https://example.com/queued.xml",
)
running_job = Job.get(Job.source == running_source)
queued_job = Job.get(Job.source == queued_source)
JobExecution.create(
job=running_job,
running_status=JobExecutionStatus.RUNNING,
started_at=reference_time - timedelta(minutes=2),
)
JobExecution.create(
job=queued_job,
running_status=JobExecutionStatus.PENDING,
)
source_feeds = cast(
tuple[dict[str, object], ...],
load_dashboard_view(log_dir=log_dir, now=reference_time)["source_feeds"],
)
assert source_feeds[0]["feed_status_label"] == "Queued"
assert source_feeds[0]["feed_status_tone"] == "queued"
assert source_feeds[0]["run_disabled"] is True
assert source_feeds[1]["feed_status_label"] == "Running"
assert source_feeds[1]["feed_status_tone"] == "scheduled"
assert source_feeds[1]["next_run"] == "Running now"
assert source_feeds[1]["run_disabled"] is True
def test_render_dashboard_shows_source_feed_links_and_statuses(
monkeypatch, tmp_path: Path
) -> None:
@ -797,13 +872,13 @@ def test_render_dashboard_shows_source_feed_links_and_statuses(
app = create_app()
app.config["REPUB_LOG_DIR"] = tmp_path / "out" / "logs"
create_source(
published_source = create_source(
name="Published source",
slug="published-source",
source_type="feed",
notes="",
spider_arguments="",
enabled=False,
enabled=True,
cron_minute="*/5",
cron_hour="*",
cron_day_of_month="*",
@ -811,7 +886,7 @@ def test_render_dashboard_shows_source_feed_links_and_statuses(
cron_month="*",
feed_url="https://example.com/published.xml",
)
create_source(
missing_source = create_source(
name="Missing source",
slug="missing-source",
source_type="feed",
@ -830,6 +905,8 @@ def test_render_dashboard_shows_source_feed_links_and_statuses(
published_feed = tmp_path / "out" / "feeds" / "published-source" / "feed.rss"
published_feed.parent.mkdir(parents=True)
published_feed.write_text("<rss/>\n", encoding="utf-8")
published_job = Job.get(Job.source == published_source)
missing_job = Job.get(Job.source == missing_source)
body = str(await render_dashboard(app))
@ -839,6 +916,11 @@ def test_render_dashboard_shows_source_feed_links_and_statuses(
assert "Available" in body
assert "Missing" in body
assert "Never published" in body
assert "Next run" in body
assert ">Run now<" in body
assert f"/actions/jobs/{published_job.id}/run-now" in body
assert f"/actions/jobs/{missing_job.id}/run-now" in body
assert "data-next-run-at" in body
asyncio.run(run())