check_step0_connections.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Run minimal DeepSeek and Redis connection checks for Step0."""
  2. from __future__ import annotations
  3. import argparse
  4. from step0_pre_prepare.connection_checks import (
  5. ConnectionCheckError,
  6. Step0ConnectionSettings,
  7. check_deepseek_connection,
  8. check_redis_connection,
  9. )
  10. def parse_args() -> argparse.Namespace:
  11. parser = argparse.ArgumentParser(description=__doc__)
  12. parser.add_argument(
  13. "service",
  14. choices=("deepseek", "redis", "all"),
  15. nargs="?",
  16. default="all",
  17. help="要测试的服务,默认测试全部",
  18. )
  19. return parser.parse_args()
  20. def main() -> int:
  21. args = parse_args()
  22. settings = Step0ConnectionSettings.from_env()
  23. checks = []
  24. if args.service in ("deepseek", "all"):
  25. checks.append(("DeepSeek", check_deepseek_connection))
  26. if args.service in ("redis", "all"):
  27. checks.append(("Redis", check_redis_connection))
  28. failed = False
  29. for label, check in checks:
  30. try:
  31. check(settings)
  32. except ConnectionCheckError as exc:
  33. failed = True
  34. print(f"[FAIL] {label}: {exc}")
  35. else:
  36. print(f"[OK] {label}: connection succeeded")
  37. return 1 if failed else 0
  38. if __name__ == "__main__":
  39. raise SystemExit(main())