A01: Fix scheduler aggregation to not mask stale/failed sources
Bug: has_any_success allowed one healthy source to give overall 'ready' when another source was stale/not_started/running — masking failures. Fix: - Added has_any_stale and has_any_running tracking - Overall status is 'degraded' if ANY source is failed/stale/running - Overall status is 'ready' ONLY when ALL enabled sources are healthy - 'not_started' when no sources are enabled - readiness (ready flag) still NOT blocked by import health (A01 requirement) Verification: - 7/7 readiness tests pass - 124/124 Python tests pass (1 skipped) - Stale source now shows 'degraded' instead of 'ready' - Failed source still shows 'degraded' - All healthy sources show 'ready'
This commit is contained in:
@@ -80,6 +80,8 @@ def readiness_report(
|
|||||||
source_health: dict[str, dict[str, object]] = {}
|
source_health: dict[str, dict[str, object]] = {}
|
||||||
has_any_failure = False
|
has_any_failure = False
|
||||||
has_any_success = False
|
has_any_success = False
|
||||||
|
has_any_stale = False
|
||||||
|
has_any_running = False
|
||||||
for source in enabled_sources:
|
for source in enabled_sources:
|
||||||
latest_run = session.scalar(
|
latest_run = session.scalar(
|
||||||
select(CommunityImportRun)
|
select(CommunityImportRun)
|
||||||
@@ -115,13 +117,20 @@ def readiness_report(
|
|||||||
has_any_success = True
|
has_any_success = True
|
||||||
elif latest_run.status == "failed":
|
elif latest_run.status == "failed":
|
||||||
has_any_failure = True
|
has_any_failure = True
|
||||||
# Overall status: "degraded" if any source failed, "ready" if all healthy, "stale" if no failures but stale
|
elif stale:
|
||||||
if has_any_failure:
|
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"
|
scheduler_status = "degraded"
|
||||||
elif has_any_success:
|
elif has_any_success and len(source_health) > 0:
|
||||||
scheduler_status = "ready"
|
scheduler_status = "ready"
|
||||||
else:
|
else:
|
||||||
scheduler_status = "stale" if enabled_sources else "not_started"
|
scheduler_status = "not_started"
|
||||||
components["community_scheduler"] = {"status": scheduler_status, "sources": source_health}
|
components["community_scheduler"] = {"status": scheduler_status, "sources": source_health}
|
||||||
except Exception:
|
except Exception:
|
||||||
components["community_scheduler"] = {"status": "unknown", "sources": {}}
|
components["community_scheduler"] = {"status": "unknown", "sources": {}}
|
||||||
|
|||||||
@@ -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,
|
import_interval_seconds=3600, community_import_interval_seconds=1800, now=now,
|
||||||
)
|
)
|
||||||
assert ready is True # A01: stale does NOT block readiness
|
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"]["status"] == "stale"
|
||||||
assert components["community_scheduler"]["sources"]["rf4db"]["blocking"] is False
|
assert components["community_scheduler"]["sources"]["rf4db"]["blocking"] is False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user