generated from coulomb/repo-seed
Implement operational discovery rescan loops
This commit is contained in:
@@ -555,6 +555,11 @@ class RegistryStore:
|
||||
if latest_discovery_snapshot
|
||||
else None
|
||||
),
|
||||
"discovery_health": (
|
||||
_discovery_snapshot_health(latest_discovery_snapshot)
|
||||
if latest_discovery_snapshot
|
||||
else {"health": "unknown", "review_required": False}
|
||||
),
|
||||
"counts": {
|
||||
"snapshots": len(self.list_snapshots(repo_slug)),
|
||||
"discovery_snapshots": len(discovery_snapshots),
|
||||
@@ -736,13 +741,42 @@ class RegistryStore:
|
||||
}
|
||||
for snapshot in self.latest_snapshots()
|
||||
]
|
||||
latest_discovery = [
|
||||
_discovery_snapshot_public_summary(snapshot)
|
||||
for snapshot in self.latest_discovery_snapshots()
|
||||
]
|
||||
return {
|
||||
"status": "ok",
|
||||
"database": str(self.path),
|
||||
"counts": counts,
|
||||
"latest_snapshots": latest,
|
||||
"latest_discovery_snapshots": latest_discovery,
|
||||
}
|
||||
|
||||
def latest_discovery_snapshots(self, profile: str | None = None) -> list[dict[str, Any]]:
|
||||
params: list[Any] = []
|
||||
where = ""
|
||||
if profile:
|
||||
where = "where profile = ?"
|
||||
params.append(profile)
|
||||
with self._connect() as db:
|
||||
rows = db.execute(
|
||||
f"""
|
||||
select ds.id, ds.repo_slug, ds.commit_sha, ds.profile, ds.generated_at,
|
||||
ds.snapshot_json, ds.accepted_graph_snapshot_id, ds.created_at
|
||||
from discovery_snapshots ds
|
||||
join (
|
||||
select repo_slug, profile, max(id) as latest_id
|
||||
from discovery_snapshots
|
||||
{where}
|
||||
group by repo_slug, profile
|
||||
) latest on latest.latest_id = ds.id
|
||||
order by ds.repo_slug, ds.profile
|
||||
""",
|
||||
params,
|
||||
).fetchall()
|
||||
return [_discovery_snapshot_dict(row) for row in rows]
|
||||
|
||||
def _latest_graph_or_empty(self, repo_slug: str) -> dict[str, Any]:
|
||||
try:
|
||||
return self.latest_snapshot(repo_slug)["graph"]
|
||||
@@ -1170,7 +1204,7 @@ def _discovery_snapshot_public_summary(snapshot: dict[str, Any]) -> dict[str, An
|
||||
candidates = snapshot["snapshot"].get("candidates", {})
|
||||
reconciliation = snapshot["snapshot"].get("reconciliation", {})
|
||||
diff = reconciliation.get("diff", {}) if isinstance(reconciliation, dict) else {}
|
||||
return {
|
||||
result = {
|
||||
"id": snapshot["id"],
|
||||
"repo_slug": snapshot["repo_slug"],
|
||||
"commit": snapshot["commit"],
|
||||
@@ -1190,6 +1224,50 @@ def _discovery_snapshot_public_summary(snapshot: dict[str, Any]) -> dict[str, An
|
||||
"conflicted": len(diff.get("conflicted", [])) if isinstance(diff.get("conflicted"), list) else 0,
|
||||
},
|
||||
}
|
||||
result.update(_discovery_snapshot_health(snapshot))
|
||||
return result
|
||||
|
||||
|
||||
def _discovery_snapshot_health(snapshot: dict[str, Any]) -> dict[str, Any]:
|
||||
payload = snapshot.get("snapshot") if isinstance(snapshot.get("snapshot"), dict) else {}
|
||||
reconciliation = payload.get("reconciliation") if isinstance(payload.get("reconciliation"), dict) else {}
|
||||
diff = reconciliation.get("diff") if isinstance(reconciliation.get("diff"), dict) else {}
|
||||
diff_counts = {
|
||||
"added": len(diff.get("added", [])) if isinstance(diff.get("added"), list) else 0,
|
||||
"changed": len(diff.get("changed", [])) if isinstance(diff.get("changed"), list) else 0,
|
||||
"retired": len(diff.get("retired", [])) if isinstance(diff.get("retired"), list) else 0,
|
||||
"conflicted": len(diff.get("conflicted", [])) if isinstance(diff.get("conflicted"), list) else 0,
|
||||
}
|
||||
review_artifact_count = (
|
||||
len(payload.get("review_artifacts", []))
|
||||
if isinstance(payload.get("review_artifacts"), list)
|
||||
else 0
|
||||
)
|
||||
connector_run_count = (
|
||||
len(payload.get("connector_runs", []))
|
||||
if isinstance(payload.get("connector_runs"), list)
|
||||
else 0
|
||||
)
|
||||
tombstone_count = (
|
||||
len(payload.get("tombstones", []))
|
||||
if isinstance(payload.get("tombstones"), list)
|
||||
else 0
|
||||
)
|
||||
review_required = bool(diff_counts["conflicted"] or review_artifact_count or tombstone_count)
|
||||
changed = any(diff_counts.values())
|
||||
if review_required:
|
||||
health = "needs_review"
|
||||
elif changed:
|
||||
health = "changed"
|
||||
else:
|
||||
health = "fresh"
|
||||
return {
|
||||
"health": health,
|
||||
"review_required": review_required,
|
||||
"review_artifact_count": review_artifact_count,
|
||||
"connector_run_count": connector_run_count,
|
||||
"tombstone_count": tombstone_count,
|
||||
}
|
||||
|
||||
|
||||
def _row_dict(row: sqlite3.Row) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user