fix(awooop): parallelize quality summary truth-chain fetch
This commit is contained in:
@@ -7,6 +7,7 @@ Telegram cards can be audited without guessing which subsystem owns the truth.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import UTC, date, datetime, timedelta
|
||||
from decimal import Decimal
|
||||
@@ -24,6 +25,7 @@ logger = structlog.get_logger(__name__)
|
||||
|
||||
_MAX_ROWS = 100
|
||||
_JSON_TEXT_FIELDS = {"gate_result", "source_envelope"}
|
||||
_QUALITY_SUMMARY_CONCURRENCY = 8
|
||||
|
||||
|
||||
def _clean(value: Any) -> Any:
|
||||
@@ -1477,17 +1479,25 @@ async def fetch_automation_quality_summary(
|
||||
},
|
||||
)
|
||||
|
||||
records: list[dict[str, Any]] = []
|
||||
for incident in incidents:
|
||||
semaphore = asyncio.Semaphore(_QUALITY_SUMMARY_CONCURRENCY)
|
||||
|
||||
async def _quality_record(incident: dict[str, Any]) -> dict[str, Any] | None:
|
||||
incident_id = str(incident.get("incident_id") or "")
|
||||
if not incident_id:
|
||||
continue
|
||||
truth_chain = await fetch_truth_chain(source_id=incident_id, project_id=project_id)
|
||||
records.append({
|
||||
return None
|
||||
async with semaphore:
|
||||
truth_chain = await fetch_truth_chain(source_id=incident_id, project_id=project_id)
|
||||
return {
|
||||
"incident": truth_chain.get("incident") or incident,
|
||||
"truth_status": truth_chain.get("truth_status") or {},
|
||||
"automation_quality": truth_chain.get("automation_quality") or {},
|
||||
})
|
||||
}
|
||||
|
||||
records = [
|
||||
record
|
||||
for record in await asyncio.gather(*(_quality_record(incident) for incident in incidents))
|
||||
if record is not None
|
||||
]
|
||||
|
||||
summary = summarize_automation_quality_records(
|
||||
project_id=project_id,
|
||||
|
||||
Reference in New Issue
Block a user