feat: ingest mainland detect result events
This commit is contained in:
@@ -38,6 +38,37 @@ def _normalize_region(value: str | None, fallback: str) -> str:
|
||||
return text
|
||||
|
||||
|
||||
_DETECT_RESULT_EVENT_TYPES = {
|
||||
"domain_started",
|
||||
"domain_completed",
|
||||
"domain_failed",
|
||||
"domain_blacklisted",
|
||||
}
|
||||
|
||||
|
||||
def _collect_recent_domain_events(active_job: dict, limit: int = 30) -> list[dict]:
|
||||
events = list(active_job.get("current_cycle_events") or active_job.get("recent_events") or [])
|
||||
normalized: list[dict] = []
|
||||
for event in reversed(events):
|
||||
event_type = str(event.get("event_type") or "").strip()
|
||||
if event_type not in _DETECT_RESULT_EVENT_TYPES:
|
||||
continue
|
||||
payload = _decode_json(event.get("payload"))
|
||||
normalized.append(
|
||||
{
|
||||
"node_code": str(event.get("node_code") or "").strip(),
|
||||
"event_type": event_type,
|
||||
"level": str(event.get("level") or "info").strip() or "info",
|
||||
"message": str(event.get("message") or "").strip(),
|
||||
"created_at": str(event.get("created_at") or "").strip(),
|
||||
"payload": payload,
|
||||
}
|
||||
)
|
||||
if limit <= 0:
|
||||
return normalized
|
||||
return normalized[-int(limit):]
|
||||
|
||||
|
||||
def _build_detect_result_batch_digest(batch: dict | None) -> dict:
|
||||
batch = batch or {}
|
||||
projection = (batch.get("projection") or {}).get("payload") or {}
|
||||
@@ -608,6 +639,7 @@ def append_detect_result_projection_if_changed(
|
||||
"label": detect.get("phase_label", ""),
|
||||
"detail": detect.get("phase_detail", ""),
|
||||
},
|
||||
"recent_domain_events": _collect_recent_domain_events(active_job, limit=30),
|
||||
}
|
||||
payload = {
|
||||
"projection": projection,
|
||||
|
||||
Reference in New Issue
Block a user