134 lines
5.4 KiB
Python
134 lines
5.4 KiB
Python
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Header
|
|
|
|
from app.schemas.common import ApiResponse
|
|
from app.services.build_info_service import get_runtime_build_info
|
|
from app.services.cluster_runtime_service import get_cluster_snapshot
|
|
from app.services.debug_event_service import get_debug_diagnosis, get_debug_event_overview, get_debug_handoff_report, ingest_debug_event, list_debug_events
|
|
from app.services.runtime_control_service import runtime_action
|
|
from app.services.runtime_status_service import get_runtime_preflight, get_runtime_status
|
|
from app.services.sync_push_service import (
|
|
ack_detect_task_projection,
|
|
export_detect_task_projection,
|
|
ingest_runtime_projection,
|
|
)
|
|
from app.services.sync_record_service import get_sync_summary, list_sync_records
|
|
|
|
router = APIRouter(tags=["runtime"])
|
|
|
|
|
|
@router.get("/runtime/status", response_model=ApiResponse)
|
|
def runtime_status() -> ApiResponse:
|
|
return ApiResponse(data=get_runtime_status())
|
|
|
|
|
|
@router.get("/runtime/readiness", response_model=ApiResponse)
|
|
def runtime_readiness() -> ApiResponse:
|
|
return ApiResponse(data=(get_runtime_status().get("readiness") or {}))
|
|
|
|
|
|
@router.get("/runtime/preflight", response_model=ApiResponse)
|
|
def runtime_preflight() -> ApiResponse:
|
|
return ApiResponse(data=get_runtime_preflight())
|
|
|
|
|
|
@router.get("/runtime/cluster", response_model=ApiResponse)
|
|
def runtime_cluster() -> ApiResponse:
|
|
return ApiResponse(data=get_cluster_snapshot())
|
|
|
|
|
|
@router.get("/runtime/build-info", response_model=ApiResponse)
|
|
def runtime_build_info() -> ApiResponse:
|
|
return ApiResponse(data=get_runtime_build_info())
|
|
|
|
|
|
@router.get("/runtime/sync-summary", response_model=ApiResponse)
|
|
def runtime_sync_summary() -> ApiResponse:
|
|
return ApiResponse(data=get_sync_summary())
|
|
|
|
|
|
@router.get("/runtime/sync-records", response_model=ApiResponse)
|
|
def runtime_sync_records(limit: int = 20) -> ApiResponse:
|
|
return ApiResponse(data={"records": list_sync_records(limit=limit)})
|
|
|
|
|
|
@router.get("/runtime/debug-events", response_model=ApiResponse)
|
|
def runtime_debug_events(
|
|
limit: int = 50,
|
|
service: Optional[str] = None,
|
|
event_type: Optional[str] = None,
|
|
source_region: Optional[str] = None,
|
|
level: Optional[str] = None,
|
|
before_id: Optional[int] = None,
|
|
after_id: Optional[int] = None,
|
|
created_after: Optional[str] = None,
|
|
) -> ApiResponse:
|
|
return ApiResponse(
|
|
data=list_debug_events(
|
|
limit=limit,
|
|
service=service,
|
|
event_type=event_type,
|
|
source_region=source_region,
|
|
level=level,
|
|
before_id=before_id,
|
|
after_id=after_id,
|
|
created_after=created_after,
|
|
)
|
|
)
|
|
|
|
|
|
@router.get("/runtime/debug-overview", response_model=ApiResponse)
|
|
def runtime_debug_overview(window_minutes: int = 10, source_region: Optional[str] = None) -> ApiResponse:
|
|
return ApiResponse(data=get_debug_event_overview(window_minutes=window_minutes, source_region=source_region))
|
|
|
|
|
|
@router.get("/runtime/debug-diagnosis", response_model=ApiResponse)
|
|
def runtime_debug_diagnosis(window_minutes: int = 10, source_region: Optional[str] = None) -> ApiResponse:
|
|
sync_summary = get_sync_summary()
|
|
return ApiResponse(data=get_debug_diagnosis(window_minutes=window_minutes, source_region=source_region, sync_summary=sync_summary))
|
|
|
|
|
|
@router.get("/runtime/debug-handoff", response_model=ApiResponse)
|
|
def runtime_debug_handoff(window_minutes: int = 10, source_region: Optional[str] = None) -> ApiResponse:
|
|
sync_summary = get_sync_summary()
|
|
runtime_status_payload = get_runtime_status()
|
|
return ApiResponse(
|
|
data=get_debug_handoff_report(
|
|
window_minutes=window_minutes,
|
|
source_region=source_region,
|
|
sync_summary=sync_summary,
|
|
readiness=runtime_status_payload.get("readiness") or {},
|
|
)
|
|
)
|
|
|
|
|
|
@router.post("/runtime/sync-ingest", response_model=ApiResponse)
|
|
def runtime_sync_ingest(payload: dict, x_domaincheck_sync_token: Optional[str] = Header(default=None)) -> ApiResponse:
|
|
ok, message, data = ingest_runtime_projection(payload, shared_token=x_domaincheck_sync_token)
|
|
return ApiResponse(code=0 if ok else 1, message=message, data=data)
|
|
|
|
|
|
@router.get("/runtime/task-export", response_model=ApiResponse)
|
|
def runtime_task_export(limit: int = 200, x_domaincheck_sync_token: Optional[str] = Header(default=None)) -> ApiResponse:
|
|
ok, message, data = export_detect_task_projection(limit=limit, shared_token=x_domaincheck_sync_token)
|
|
return ApiResponse(code=0 if ok else 1, message=message, data=data)
|
|
|
|
|
|
@router.post("/runtime/task-ack", response_model=ApiResponse)
|
|
def runtime_task_ack(payload: dict, x_domaincheck_sync_token: Optional[str] = Header(default=None)) -> ApiResponse:
|
|
ok, message, data = ack_detect_task_projection(payload, shared_token=x_domaincheck_sync_token)
|
|
return ApiResponse(code=0 if ok else 1, message=message, data=data)
|
|
|
|
|
|
@router.post("/runtime/debug-ingest", response_model=ApiResponse)
|
|
def runtime_debug_ingest(payload: dict, x_domaincheck_sync_token: Optional[str] = Header(default=None)) -> ApiResponse:
|
|
ok, message, data = ingest_debug_event(payload, shared_token=x_domaincheck_sync_token)
|
|
return ApiResponse(code=0 if ok else 1, message=message, data=data)
|
|
|
|
|
|
@router.post("/runtime/actions/{action}", response_model=ApiResponse)
|
|
def runtime_action_trigger(action: str) -> ApiResponse:
|
|
ok, message, data = runtime_action(action)
|
|
return ApiResponse(code=0 if ok else 1, message=message, data=data)
|