mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-07 09:13:04 +02:00
Consolidate healthcheck generation and packet dupe handling
This commit is contained in:
+3
-28
@@ -3,13 +3,10 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from fastapi import WebSocket
|
||||
|
||||
from app.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Timeout for individual WebSocket send operations (seconds)
|
||||
@@ -128,33 +125,11 @@ def broadcast_success(message: str, details: str | None = None) -> None:
|
||||
|
||||
def broadcast_health(radio_connected: bool, serial_port: str | None = None) -> None:
|
||||
"""Broadcast health status change to all connected clients."""
|
||||
from app.repository import RawPacketRepository
|
||||
|
||||
async def _broadcast():
|
||||
# Get database file size in MB
|
||||
db_size_mb = 0.0
|
||||
try:
|
||||
db_size_bytes = os.path.getsize(settings.database_path)
|
||||
db_size_mb = round(db_size_bytes / (1024 * 1024), 2)
|
||||
except OSError:
|
||||
pass
|
||||
from app.routers.health import build_health_data
|
||||
|
||||
# Get oldest undecrypted packet info
|
||||
oldest_ts = None
|
||||
try:
|
||||
oldest_ts = await RawPacketRepository.get_oldest_undecrypted()
|
||||
except RuntimeError:
|
||||
pass # Database not connected
|
||||
|
||||
await ws_manager.broadcast(
|
||||
"health",
|
||||
{
|
||||
"status": "ok" if radio_connected else "degraded",
|
||||
"radio_connected": radio_connected,
|
||||
"serial_port": serial_port,
|
||||
"database_size_mb": db_size_mb,
|
||||
"oldest_undecrypted_timestamp": oldest_ts,
|
||||
},
|
||||
)
|
||||
data = await build_health_data(radio_connected, serial_port)
|
||||
await ws_manager.broadcast("health", data)
|
||||
|
||||
asyncio.create_task(_broadcast())
|
||||
|
||||
Reference in New Issue
Block a user