This commit is contained in:
Your Name
2026-04-17 14:07:50 +08:00
parent dc34a4e294
commit 1921318c25
11 changed files with 2415 additions and 19 deletions

View File

@@ -38,6 +38,40 @@ def _normalize_region(value: str | None, fallback: str) -> str:
return text
def _build_detect_result_batch_digest(batch: dict | None) -> dict:
batch = batch or {}
projection = (batch.get("projection") or {}).get("payload") or {}
latest_push = batch.get("latest_push") or {}
latest_ingest = batch.get("latest_ingest") or {}
job = (projection.get("projection") or {}).get("job") or {}
latest_event = (projection.get("projection") or {}).get("latest_event") or {}
return {
"job_id": int(batch.get("job_id") or 0),
"job_code": str(batch.get("job_code") or ""),
"job_status": str(batch.get("job_status") or ""),
"items_total": int(batch.get("items_total") or 0),
"items_terminal": int(batch.get("items_terminal") or 0),
"items_pending": int(batch.get("items_pending") or 0),
"items_running": int(batch.get("items_running") or 0),
"items_failed": int(batch.get("items_failed") or 0),
"progress_percent": float(batch.get("progress_percent") or 0),
"sync_state": str(batch.get("sync_state") or "unsynced"),
"sync_message": str(batch.get("sync_message") or ""),
"projection_record_id": int((batch.get("projection") or {}).get("id") or 0),
"projection_status": str((batch.get("projection") or {}).get("status") or ""),
"projection_created_at": str((batch.get("projection") or {}).get("created_at") or ""),
"latest_event_type": str(latest_event.get("event_type") or ""),
"latest_event_message": str(latest_event.get("message") or ""),
"latest_event_created_at": str(latest_event.get("created_at") or ""),
"latest_push_status": str(latest_push.get("status") or ""),
"latest_push_error": str(latest_push.get("error_message") or ""),
"latest_push_created_at": str(latest_push.get("created_at") or ""),
"latest_ingest_status": str(latest_ingest.get("status") or ""),
"latest_ingest_created_at": str(latest_ingest.get("created_at") or ""),
"cycle_token": str(job.get("current_cycle_token") or ""),
}
def _should_append_runtime_projection(previous_payload: dict, current_projection: dict, previous_created_at: datetime | None) -> bool:
if not previous_payload:
return True
@@ -346,6 +380,10 @@ def get_sync_summary(record_limit: int = 10) -> dict:
"updated_at": _format_time(latest[8]),
}
detect_result_batches = get_detect_result_sync_batches(limit=min(5, record_limit))
recent_result_batches = list(detect_result_batches.get("batches") or [])
latest_result_batch = recent_result_batches[0] if recent_result_batches else None
return {
"enabled": bool(settings.sync_push_enabled),
"source_region": source_region,
@@ -357,7 +395,9 @@ def get_sync_summary(record_limit: int = 10) -> dict:
"status_counts": status_counts,
"type_counts": type_counts,
"latest_record": latest_record,
"detect_result_batches": get_detect_result_sync_batches(limit=min(5, record_limit)),
"detect_result_batches": detect_result_batches,
"latest_detect_result_batch": _build_detect_result_batch_digest(latest_result_batch),
"detect_result_batch_digests": [_build_detect_result_batch_digest(item) for item in recent_result_batches],
"recent_records": list_sync_records(limit=record_limit),
}