feat add connections management and health summary improvements

This commit is contained in:
2026-03-15 16:40:43 +03:00
parent eba0fab091
commit 027d17f193
17 changed files with 8521 additions and 10819 deletions

View File

@@ -8,6 +8,7 @@
# @RELATION: DEPENDS_ON -> backend.src.core.task_manager.cleanup.TaskCleanupService
from typing import List, Dict, Any, Optional, Tuple
import time
from sqlalchemy.orm import Session
from sqlalchemy import func, desc
import os
@@ -24,6 +25,9 @@ from ..core.task_manager import TaskManager
# @RELATION: CALLS -> backend.src.core.superset_client.SupersetClient
# @RELATION: CALLS -> backend.src.core.task_manager.cleanup.TaskCleanupService
class HealthService:
_dashboard_summary_cache: Dict[str, Tuple[float, Dict[str, Dict[str, Optional[str]]]]] = {}
_dashboard_summary_cache_ttl_seconds = 60.0
"""
@PURPOSE: Service for managing and querying dashboard health data.
"""
@@ -77,15 +81,27 @@ class HealthService:
continue
try:
dashboards = SupersetClient(env).get_dashboards_summary()
dashboard_meta_map = {
str(item.get("id")): {
"slug": item.get("slug"),
"title": item.get("title"),
cached_meta = self.__class__._dashboard_summary_cache.get(environment_id)
cache_is_fresh = (
cached_meta is not None
and (time.monotonic() - cached_meta[0]) < self.__class__._dashboard_summary_cache_ttl_seconds
)
if cache_is_fresh:
dashboard_meta_map = cached_meta[1]
else:
dashboards = SupersetClient(env).get_dashboards_summary()
dashboard_meta_map = {
str(item.get("id")): {
"slug": item.get("slug"),
"title": item.get("title"),
}
for item in dashboards
if str(item.get("id") or "").strip()
}
for item in dashboards
if str(item.get("id") or "").strip()
}
self.__class__._dashboard_summary_cache[environment_id] = (
time.monotonic(),
dashboard_meta_map,
)
for dashboard_id in dashboard_ids:
self._dashboard_meta_cache[(environment_id, dashboard_id)] = dashboard_meta_map.get(
dashboard_id,