fix: audit P0-P1 — T03-T07, D01-D08, U01-U02 (#1788956171115)
This commit is contained in:
@@ -6,12 +6,13 @@ from typing import Any
|
||||
from sqlalchemy import select, text
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .models import ImportStatus, OfficialRecordImport
|
||||
from .models import CommunityImportRun, ImportStatus, OfficialRecordImport
|
||||
|
||||
|
||||
def readiness_report(
|
||||
session: Session, s3: Any, *, import_required: bool,
|
||||
import_interval_seconds: int, now: datetime | None = None,
|
||||
import_interval_seconds: int, community_import_interval_seconds: int = 1800,
|
||||
now: datetime | None = None,
|
||||
) -> tuple[bool, dict[str, dict[str, object]]]:
|
||||
current = now or datetime.now(timezone.utc)
|
||||
components: dict[str, dict[str, object]] = {}
|
||||
@@ -58,4 +59,26 @@ def readiness_report(
|
||||
if import_required:
|
||||
ready = False
|
||||
|
||||
# Check community scheduler: look for recent import runs
|
||||
try:
|
||||
latest_community = session.scalar(
|
||||
select(CommunityImportRun)
|
||||
.order_by(CommunityImportRun.started_at.desc())
|
||||
.limit(1)
|
||||
)
|
||||
if latest_community is None:
|
||||
components["community_scheduler"] = {"status": "not_started"}
|
||||
else:
|
||||
started = latest_community.started_at
|
||||
if started.tzinfo is None:
|
||||
started = started.replace(tzinfo=timezone.utc)
|
||||
stale = started < current - timedelta(seconds=community_import_interval_seconds * 2)
|
||||
healthy = latest_community.status == "success" and not stale
|
||||
components["community_scheduler"] = {
|
||||
"status": "ready" if healthy else ("stale" if stale else latest_community.status),
|
||||
"last_started_at": started.isoformat(),
|
||||
}
|
||||
except Exception:
|
||||
components["community_scheduler"] = {"status": "unknown"}
|
||||
|
||||
return ready, components
|
||||
|
||||
Reference in New Issue
Block a user