update check active
This commit is contained in:
@@ -4,6 +4,9 @@ import uuid
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, HTTPException
|
||||
|
||||
from app.core.command_runner import CommandRunner
|
||||
from app.core.installer import AptInstaller
|
||||
from app.core.service_manager import ServiceManager
|
||||
from app.core.task_runner import TaskRunner
|
||||
from app.models.schemas import InstallRequest, RemoveRequest, UpdateRequest
|
||||
from app.storage.repository import Repository
|
||||
@@ -20,7 +23,56 @@ def _task_id(prefix: str) -> str:
|
||||
|
||||
@router.get("/installed")
|
||||
def installed_apps() -> list[dict]:
|
||||
return repository.list_installed_apps()
|
||||
apps = repository.list_installed_apps()
|
||||
command_runner = CommandRunner(repository)
|
||||
service_manager = ServiceManager(command_runner)
|
||||
apt_installer = AptInstaller(command_runner)
|
||||
for app in apps:
|
||||
service_checks: list[dict] = []
|
||||
component_statuses: list[str] = []
|
||||
for component in repository.list_installed_components(app["app_id"]):
|
||||
check_status = component.get("service_check_status", "not-checked")
|
||||
if check_status != "not-checked":
|
||||
component_statuses.append(check_status)
|
||||
for check in component.get("service_checks", []):
|
||||
service_name = str(check.get("serviceName") or "").strip()
|
||||
if not service_name:
|
||||
continue
|
||||
current_check = service_manager.get_service_status(service_name)
|
||||
if current_check.get("status") == "unknown" and current_check.get("errorMessage"):
|
||||
current_check = dict(check)
|
||||
current_check["stale"] = True
|
||||
elif check.get("readinessType") == "postgresql":
|
||||
readiness_status = "ready" if apt_installer.is_postgresql_ready() else "failed"
|
||||
current_check["readinessType"] = "postgresql"
|
||||
current_check["readinessStatus"] = readiness_status
|
||||
current_check["healthy"] = bool(current_check.get("healthy")) and readiness_status == "ready"
|
||||
service_checks.append(
|
||||
{
|
||||
**current_check,
|
||||
"componentId": component["component_id"],
|
||||
"packageName": component.get("package_name"),
|
||||
}
|
||||
)
|
||||
|
||||
if service_checks and any(not check.get("healthy") for check in service_checks):
|
||||
overall_status = "unhealthy"
|
||||
elif service_checks:
|
||||
overall_status = "healthy"
|
||||
elif "unhealthy" in component_statuses:
|
||||
overall_status = "unhealthy"
|
||||
elif "checking" in component_statuses:
|
||||
overall_status = "checking"
|
||||
elif "healthy" in component_statuses:
|
||||
overall_status = "healthy"
|
||||
elif "not-applicable" in component_statuses:
|
||||
overall_status = "not-applicable"
|
||||
else:
|
||||
overall_status = "not-checked"
|
||||
|
||||
app["serviceCheckStatus"] = overall_status
|
||||
app["serviceChecks"] = service_checks
|
||||
return apps
|
||||
|
||||
|
||||
@router.post("/install")
|
||||
|
||||
Reference in New Issue
Block a user