diff --git a/apps/api/app/readiness.py b/apps/api/app/readiness.py index 7a17e70..c2e878b 100644 --- a/apps/api/app/readiness.py +++ b/apps/api/app/readiness.py @@ -80,6 +80,8 @@ def readiness_report( source_health: dict[str, dict[str, object]] = {} has_any_failure = False has_any_success = False + has_any_stale = False + has_any_running = False for source in enabled_sources: latest_run = session.scalar( select(CommunityImportRun) @@ -115,13 +117,20 @@ def readiness_report( has_any_success = True elif latest_run.status == "failed": has_any_failure = True - # Overall status: "degraded" if any source failed, "ready" if all healthy, "stale" if no failures but stale - if has_any_failure: + elif stale: + has_any_stale = True + elif latest_run.status == "running": + has_any_running = True + # Overall status: never mask failures with success of another source + # "degraded" if any source failed/stale/running + # "ready" only when ALL enabled sources are healthy + # "not_started" when no sources are enabled + if has_any_failure or has_any_stale or has_any_running: scheduler_status = "degraded" - elif has_any_success: + elif has_any_success and len(source_health) > 0: scheduler_status = "ready" else: - scheduler_status = "stale" if enabled_sources else "not_started" + scheduler_status = "not_started" components["community_scheduler"] = {"status": scheduler_status, "sources": source_health} except Exception: components["community_scheduler"] = {"status": "unknown", "sources": {}} diff --git a/apps/api/tests/test_readiness.py b/apps/api/tests/test_readiness.py index 87363eb..79f9184 100644 --- a/apps/api/tests/test_readiness.py +++ b/apps/api/tests/test_readiness.py @@ -123,7 +123,7 @@ def test_community_scheduler_stale_does_not_block_readiness() -> None: import_interval_seconds=3600, community_import_interval_seconds=1800, now=now, ) assert ready is True # A01: stale does NOT block readiness - assert components["community_scheduler"]["status"] == "stale" # Overall reflects stale source + assert components["community_scheduler"]["status"] == "degraded" # Stale source shows as degraded assert components["community_scheduler"]["sources"]["rf4db"]["status"] == "stale" assert components["community_scheduler"]["sources"]["rf4db"]["blocking"] is False