output to out/feeds/*
This commit is contained in:
parent
beac981047
commit
6fd3b598ab
11 changed files with 298 additions and 16 deletions
|
|
@ -11,6 +11,7 @@ from typing import Callable, TextIO, cast
|
|||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
|
||||
from repub.config import feed_output_dir, feed_output_path
|
||||
from repub.model import Job, JobExecution, JobExecutionStatus, Source, database, utc_now
|
||||
|
||||
SCHEDULER_JOB_PREFIX = "job-"
|
||||
|
|
@ -401,6 +402,7 @@ def load_dashboard_view(
|
|||
runs_view = load_runs_view(log_dir=log_dir, now=reference_time)
|
||||
output_dir = Path(log_dir).parent
|
||||
with database.connection_context():
|
||||
sources = tuple(Source.select().order_by(Source.name.asc()))
|
||||
failed_last_day = (
|
||||
JobExecution.select()
|
||||
.where(
|
||||
|
|
@ -416,6 +418,10 @@ def load_dashboard_view(
|
|||
footprint_bytes = _directory_size(output_dir)
|
||||
return {
|
||||
"running": runs_view["running"],
|
||||
"source_feeds": tuple(
|
||||
_project_source_feed(source, output_dir, reference_time)
|
||||
for source in sources
|
||||
),
|
||||
"snapshot": {
|
||||
"running_now": str(len(runs_view["running"])),
|
||||
"upcoming_today": str(upcoming_ready),
|
||||
|
|
@ -605,6 +611,35 @@ def _project_completed_execution(
|
|||
}
|
||||
|
||||
|
||||
def _project_source_feed(
|
||||
source: Source, output_dir: Path, reference_time: datetime
|
||||
) -> dict[str, object]:
|
||||
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)
|
||||
feed_exists = feed_path.exists()
|
||||
updated_at = (
|
||||
datetime.fromtimestamp(feed_path.stat().st_mtime, tz=UTC)
|
||||
if feed_exists
|
||||
else None
|
||||
)
|
||||
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_exists": feed_exists,
|
||||
"last_updated": (
|
||||
_humanize_relative_time(reference_time, updated_at)
|
||||
if updated_at is not None
|
||||
else "Never published"
|
||||
),
|
||||
"last_updated_iso": updated_at.isoformat() if updated_at is not None else None,
|
||||
"artifact_footprint": _format_bytes(_directory_size(source_dir)),
|
||||
}
|
||||
|
||||
|
||||
def _execution_status_label(execution: JobExecution) -> str:
|
||||
status = JobExecutionStatus(execution.running_status)
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue