fix(awooop): surface legacy HITL backlog
This commit is contained in:
@@ -20,6 +20,7 @@ from pydantic import BaseModel
|
||||
from src.core.config import settings
|
||||
from src.core.logging import get_logger
|
||||
from src.core.sse import EventPublisher, EventType, SSEEvent, get_publisher
|
||||
from src.services.dashboard_metrics_service import fetch_pending_approval_count
|
||||
from src.services.host_aggregator import AggregatedStatus, HostAggregator
|
||||
|
||||
router = APIRouter()
|
||||
@@ -141,12 +142,14 @@ async def dashboard_update_loop(publisher: EventPublisher) -> None:
|
||||
try:
|
||||
# Fetch aggregated status
|
||||
status = await HostAggregator.fetch_all()
|
||||
pending_approvals = await fetch_pending_approval_count()
|
||||
|
||||
# Publish to all connected clients
|
||||
event = SSEEvent(
|
||||
type=EventType.HOST_UPDATE,
|
||||
data={
|
||||
"overall_status": status.overall_status,
|
||||
"pending_approvals": pending_approvals,
|
||||
"hosts": [
|
||||
{
|
||||
"ip": h.ip,
|
||||
@@ -206,7 +209,9 @@ async def get_dashboard() -> DashboardResponse:
|
||||
logger.info("dashboard_fetch")
|
||||
|
||||
status = await HostAggregator.fetch_all()
|
||||
return aggregated_to_response(status)
|
||||
response = aggregated_to_response(status)
|
||||
response.pending_approvals = await fetch_pending_approval_count()
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/dashboard/stream")
|
||||
|
||||
31
apps/api/src/services/dashboard_metrics_service.py
Normal file
31
apps/api/src/services/dashboard_metrics_service.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Dashboard Metrics Service
|
||||
=========================
|
||||
Small DB-backed counters used by the war-room dashboard.
|
||||
"""
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from src.core.logging import get_logger
|
||||
from src.db.base import get_db_context
|
||||
|
||||
logger = get_logger("awoooi.dashboard_metrics")
|
||||
|
||||
|
||||
async def fetch_pending_approval_count() -> int:
|
||||
"""Read the live HITL backlog from approval_records."""
|
||||
try:
|
||||
async with get_db_context() as db:
|
||||
result = await db.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT count(*)
|
||||
FROM approval_records
|
||||
WHERE upper(status::text) = 'PENDING'
|
||||
"""
|
||||
)
|
||||
)
|
||||
return int(result.scalar_one() or 0)
|
||||
except Exception as exc:
|
||||
logger.warning("dashboard_pending_approval_count_failed", error=str(exc))
|
||||
return 0
|
||||
Reference in New Issue
Block a user