feat: stabilize multi-region runtime sync and worker orchestration
This commit is contained in:
@@ -19,6 +19,55 @@ from app.services.sync_record_service import get_sync_summary, list_sync_records
|
||||
router = APIRouter(tags=["runtime"])
|
||||
|
||||
|
||||
def _filter_debug_handover_by_node_code(payload: dict, node_code: str) -> dict:
|
||||
normalized_node_code = str(node_code or "").strip()
|
||||
if not normalized_node_code:
|
||||
return dict(payload or {})
|
||||
|
||||
normalized_payload = dict(payload or {})
|
||||
|
||||
def _matches_node(item: object) -> bool:
|
||||
if not isinstance(item, dict):
|
||||
return False
|
||||
return str(item.get("node_code") or "").strip() == normalized_node_code
|
||||
|
||||
overview = dict(normalized_payload.get("overview") or {})
|
||||
if overview:
|
||||
overview["recent_issues"] = [
|
||||
item
|
||||
for item in list(overview.get("recent_issues") or [])
|
||||
if _matches_node(item)
|
||||
]
|
||||
normalized_payload["overview"] = overview
|
||||
|
||||
normalized_payload["recent_issues"] = [
|
||||
item
|
||||
for item in list(normalized_payload.get("recent_issues") or [])
|
||||
if _matches_node(item)
|
||||
]
|
||||
normalized_payload["issue_groups"] = [
|
||||
item
|
||||
for item in list(normalized_payload.get("issue_groups") or [])
|
||||
if _matches_node(item)
|
||||
]
|
||||
|
||||
failure_handoff = dict(normalized_payload.get("failure_handoff") or {})
|
||||
if failure_handoff:
|
||||
failure_handoff["recent_issues"] = [
|
||||
item
|
||||
for item in list(failure_handoff.get("recent_issues") or [])
|
||||
if _matches_node(item)
|
||||
]
|
||||
failure_handoff["issue_groups"] = [
|
||||
item
|
||||
for item in list(failure_handoff.get("issue_groups") or [])
|
||||
if _matches_node(item)
|
||||
]
|
||||
normalized_payload["failure_handoff"] = failure_handoff
|
||||
|
||||
return normalized_payload
|
||||
|
||||
|
||||
@router.get("/runtime/status", response_model=ApiResponse)
|
||||
def runtime_status() -> ApiResponse:
|
||||
return ApiResponse(data=get_runtime_status())
|
||||
@@ -60,6 +109,7 @@ def runtime_debug_events(
|
||||
service: Optional[str] = None,
|
||||
event_type: Optional[str] = None,
|
||||
source_region: Optional[str] = None,
|
||||
node_code: Optional[str] = None,
|
||||
level: Optional[str] = None,
|
||||
before_id: Optional[int] = None,
|
||||
after_id: Optional[int] = None,
|
||||
@@ -71,6 +121,7 @@ def runtime_debug_events(
|
||||
service=service,
|
||||
event_type=event_type,
|
||||
source_region=source_region,
|
||||
node_code=node_code,
|
||||
level=level,
|
||||
before_id=before_id,
|
||||
after_id=after_id,
|
||||
@@ -125,12 +176,7 @@ def runtime_health_handover(
|
||||
)
|
||||
normalized_node_code = str(node_code or "").strip()
|
||||
if normalized_node_code:
|
||||
data = dict(data)
|
||||
data["nodes"] = [
|
||||
item
|
||||
for item in list(data.get("nodes") or [])
|
||||
if str(item.get("node_code") or "").strip() == normalized_node_code
|
||||
]
|
||||
data = _filter_debug_handover_by_node_code(data, normalized_node_code)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user