Compare commits
1 Commits
mimo/resea
...
mimo/build
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
237aeaaca0 |
@@ -586,8 +586,8 @@ def alert_on_failure(report: HealthReport, dry_run: bool = False) -> None:
|
||||
logger.info("Created alert issue #%d", result["number"])
|
||||
|
||||
|
||||
def run_once(args: argparse.Namespace) -> bool:
|
||||
"""Run one health check cycle. Returns True if healthy."""
|
||||
def run_once(args: argparse.Namespace) -> tuple[bool, HealthReport]:
|
||||
"""Run one health check cycle. Returns (healthy, report)."""
|
||||
report = run_health_checks(
|
||||
ws_host=args.ws_host,
|
||||
ws_port=args.ws_port,
|
||||
@@ -615,7 +615,20 @@ def run_once(args: argparse.Namespace) -> bool:
|
||||
except Exception:
|
||||
pass # never crash the watchdog over its own heartbeat
|
||||
|
||||
return report.overall_healthy
|
||||
return report.overall_healthy, report
|
||||
|
||||
|
||||
def _emit_json(report: HealthReport) -> None:
|
||||
"""Print a HealthReport as JSON to stdout."""
|
||||
print(json.dumps({
|
||||
"healthy": report.overall_healthy,
|
||||
"timestamp": report.timestamp,
|
||||
"checks": [
|
||||
{"name": c.name, "healthy": c.healthy,
|
||||
"message": c.message, "details": c.details}
|
||||
for c in report.checks
|
||||
],
|
||||
}, indent=2))
|
||||
|
||||
|
||||
def main():
|
||||
@@ -678,30 +691,18 @@ def main():
|
||||
signal.signal(signal.SIGINT, _handle_sigterm)
|
||||
|
||||
while _running:
|
||||
run_once(args)
|
||||
_healthy, report = run_once(args)
|
||||
if args.output_json:
|
||||
_emit_json(report)
|
||||
for _ in range(args.interval):
|
||||
if not _running:
|
||||
break
|
||||
time.sleep(1)
|
||||
else:
|
||||
healthy = run_once(args)
|
||||
healthy, report = run_once(args)
|
||||
|
||||
if args.output_json:
|
||||
report = run_health_checks(
|
||||
ws_host=args.ws_host,
|
||||
ws_port=args.ws_port,
|
||||
heartbeat_path=Path(args.heartbeat_path),
|
||||
stale_threshold=args.stale_threshold,
|
||||
)
|
||||
print(json.dumps({
|
||||
"healthy": report.overall_healthy,
|
||||
"timestamp": report.timestamp,
|
||||
"checks": [
|
||||
{"name": c.name, "healthy": c.healthy,
|
||||
"message": c.message, "details": c.details}
|
||||
for c in report.checks
|
||||
],
|
||||
}, indent=2))
|
||||
_emit_json(report)
|
||||
|
||||
sys.exit(0 if healthy else 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user