Enhance dashboard published feeds controls
This commit is contained in:
parent
e796e09d14
commit
ca3d34053f
5 changed files with 177 additions and 29 deletions
|
|
@ -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)),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue