Coverage for flask/src/healthz.py: 76%
11 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-28 13:33 +0900
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-28 13:33 +0900
1#!/usr/bin/env python3
2"""
3Liveness のチェックを行います
5Usage:
6 healthz.py [-c CONFIG] [-p PORT] [-D]
8Options:
9 -c CONFIG : CONFIG を設定ファイルとして読み込んで実行します。[default: config.yaml]
10 -p PORT : WEB サーバのポートを指定します。[default: 5000]
11 -D : デバッグモードで動作します。
12"""
14import logging
15import pathlib
16import sys
18import my_lib.healthz
21def check_liveness(target_list, port=None):
22 for target in target_list:
23 if not my_lib.healthz.check_liveness(target["name"], target["liveness_file"], target["interval"]): 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true
24 return False
26 if port is not None: 26 ↛ 27line 26 didn't jump to line 27 because the condition on line 26 was never true
27 return my_lib.healthz.check_port(port)
28 else:
29 return True
32if __name__ == "__main__":
33 import docopt
34 import my_lib.config
35 import my_lib.logger
37 args = docopt.docopt(__doc__)
39 config_file = args["-c"]
40 port = args["-p"]
41 debug_mode = args["-D"]
43 my_lib.logger.init("hems.rasp-water", level=logging.DEBUG if debug_mode else logging.INFO)
45 config = my_lib.config.load(config_file)
47 target_list = [
48 {
49 "name": name,
50 "liveness_file": pathlib.Path(config["liveness"]["file"][name]),
51 "interval": 10,
52 }
53 for name in ["scheduler"]
54 ]
56 if check_liveness(target_list, port):
57 logging.info("OK.")
58 sys.exit(0)
59 else:
60 sys.exit(-1)