Coverage for src / healthz.py: 0%

4 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-02-13 00:10 +0900

1#!/usr/bin/env python3 

2""" 

3Liveness のチェックを行います 

4 

5Usage: 

6 healthz.py [-c CONFIG] [-p PORT] [-D] 

7 

8Options: 

9 -c CONFIG : CONFIG を設定ファイルとして読み込んで実行します。[default: config.yaml] 

10 -p PORT : WEB サーバのポートを指定します。[default: 5000] 

11 -D : デバッグモードで動作します。 

12""" 

13 

14import logging 

15import pathlib 

16import sys 

17 

18import my_lib.healthz 

19 

20if __name__ == "__main__": 

21 import docopt 

22 import my_lib.config 

23 import my_lib.logger 

24 

25 # docstringを使用(__doc__がNoneでないことを確認) 

26 assert __doc__ is not None, "Module docstring is required" # noqa: S101 

27 args = docopt.docopt(__doc__) 

28 

29 config_file = args["-c"] 

30 port = args["-p"] 

31 debug_mode = args["-D"] 

32 

33 my_lib.logger.init("hems.rasp-water", level=logging.DEBUG if debug_mode else logging.INFO) 

34 

35 config = my_lib.config.load(config_file) 

36 

37 target_list = [ 

38 my_lib.healthz.HealthzTarget( 

39 name=name, 

40 liveness_file=pathlib.Path(config["liveness"]["file"][name]), 

41 interval=10, 

42 ) 

43 for name in ["scheduler"] 

44 ] 

45 

46 # my_libの型スタブが最新でないため、メソッド名をmypyが認識しない 

47 failed_targets = my_lib.healthz.check_liveness_all_with_ports( # type: ignore[attr-defined] 

48 target_list, 

49 http_port=port, 

50 ) 

51 

52 if not failed_targets: 

53 logging.info("OK.") 

54 sys.exit(0) 

55 else: 

56 sys.exit(-1)