refactor: reuse cached reachability lookup in service health
Agent-Logs-Url: https://github.com/naturallaw777/staging_alpha/sessions/3208f380-e8fe-4f12-b83c-723ecee6cd4c Co-authored-by: naturallaw777 <99053422+naturallaw777@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9c34eb0694
commit
5bb8af7a3e
@@ -2378,6 +2378,16 @@ async def api_services():
|
|||||||
domain = val if val else None
|
domain = val if val else None
|
||||||
except OSError:
|
except OSError:
|
||||||
domain = None
|
domain = None
|
||||||
|
cached_reachable: bool | None = None
|
||||||
|
domain_reachability = None
|
||||||
|
if needs_domain and domain and enabled:
|
||||||
|
cached_reachable = _is_domain_reachable_cached(domain)
|
||||||
|
if cached_reachable is None:
|
||||||
|
domain_reachability = "checking"
|
||||||
|
elif cached_reachable:
|
||||||
|
domain_reachability = "reachable"
|
||||||
|
else:
|
||||||
|
domain_reachability = "unreachable"
|
||||||
|
|
||||||
# Compute composite health
|
# Compute composite health
|
||||||
sync_progress: float | None = None
|
sync_progress: float | None = None
|
||||||
@@ -2400,7 +2410,6 @@ async def api_services():
|
|||||||
has_port_issues = True
|
has_port_issues = True
|
||||||
break
|
break
|
||||||
has_domain_issues = False
|
has_domain_issues = False
|
||||||
cached_reachable: bool | None = None
|
|
||||||
if needs_domain:
|
if needs_domain:
|
||||||
has_domain_issues = await loop.run_in_executor(
|
has_domain_issues = await loop.run_in_executor(
|
||||||
None,
|
None,
|
||||||
@@ -2409,15 +2418,12 @@ async def api_services():
|
|||||||
_cached_external_ip,
|
_cached_external_ip,
|
||||||
)
|
)
|
||||||
if not has_domain_issues and domain:
|
if not has_domain_issues and domain:
|
||||||
cached_reachable = _is_domain_reachable_cached(domain)
|
|
||||||
if cached_reachable is False:
|
if cached_reachable is False:
|
||||||
has_domain_issues = True
|
has_domain_issues = True
|
||||||
if has_port_issues or has_domain_issues:
|
if has_port_issues or has_domain_issues:
|
||||||
health = "needs_attention"
|
health = "needs_attention"
|
||||||
else:
|
else:
|
||||||
if needs_domain and domain:
|
if needs_domain and domain:
|
||||||
if cached_reachable is None:
|
|
||||||
cached_reachable = _is_domain_reachable_cached(domain)
|
|
||||||
health = "checking_reachability" if cached_reachable is None else "healthy"
|
health = "checking_reachability" if cached_reachable is None else "healthy"
|
||||||
else:
|
else:
|
||||||
health = "healthy"
|
health = "healthy"
|
||||||
@@ -2435,7 +2441,6 @@ async def api_services():
|
|||||||
# still check domain/port health so status remains consistent with
|
# still check domain/port health so status remains consistent with
|
||||||
# other domain services when there are actionable issues.
|
# other domain services when there are actionable issues.
|
||||||
has_domain_issues = False
|
has_domain_issues = False
|
||||||
cached_reachable: bool | None = None
|
|
||||||
if needs_domain:
|
if needs_domain:
|
||||||
has_domain_issues = await loop.run_in_executor(
|
has_domain_issues = await loop.run_in_executor(
|
||||||
None,
|
None,
|
||||||
@@ -2444,7 +2449,6 @@ async def api_services():
|
|||||||
_cached_external_ip,
|
_cached_external_ip,
|
||||||
)
|
)
|
||||||
if not has_domain_issues and domain:
|
if not has_domain_issues and domain:
|
||||||
cached_reachable = _is_domain_reachable_cached(domain)
|
|
||||||
if cached_reachable is False:
|
if cached_reachable is False:
|
||||||
has_domain_issues = True
|
has_domain_issues = True
|
||||||
has_port_issues = False
|
has_port_issues = False
|
||||||
@@ -2462,8 +2466,6 @@ async def api_services():
|
|||||||
if has_domain_issues or has_port_issues:
|
if has_domain_issues or has_port_issues:
|
||||||
health = "needs_attention"
|
health = "needs_attention"
|
||||||
elif needs_domain and domain:
|
elif needs_domain and domain:
|
||||||
if cached_reachable is None:
|
|
||||||
cached_reachable = _is_domain_reachable_cached(domain)
|
|
||||||
health = "checking_reachability" if cached_reachable is None else "inactive"
|
health = "checking_reachability" if cached_reachable is None else "inactive"
|
||||||
else:
|
else:
|
||||||
health = "inactive"
|
health = "inactive"
|
||||||
@@ -2472,16 +2474,6 @@ async def api_services():
|
|||||||
else:
|
else:
|
||||||
health = status # loading states, etc.
|
health = status # loading states, etc.
|
||||||
|
|
||||||
domain_reachability = None
|
|
||||||
if needs_domain and domain and enabled:
|
|
||||||
cached = _is_domain_reachable_cached(domain)
|
|
||||||
if cached is None:
|
|
||||||
domain_reachability = "checking"
|
|
||||||
elif cached:
|
|
||||||
domain_reachability = "reachable"
|
|
||||||
else:
|
|
||||||
domain_reachability = "unreachable"
|
|
||||||
|
|
||||||
service_data: dict = {
|
service_data: dict = {
|
||||||
"name": entry.get("name", ""),
|
"name": entry.get("name", ""),
|
||||||
"unit": unit,
|
"unit": unit,
|
||||||
|
|||||||
Reference in New Issue
Block a user