Coverage for flask/src/healthz.py: 76%
11 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-24 13:56 +0900
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-24 13:56 +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
32######################################################################
33if __name__ == "__main__":
34 import docopt
35 import my_lib.config
36 import my_lib.logger
38 args = docopt.docopt(__doc__)
40 config_file = args["-c"]
41 port = args["-p"]
42 debug_mode = args["-d"]
44 my_lib.logger.init("hems.rasp-water", level=logging.DEBUG if debug_mode else logging.INFO)
46 logging.info("Using config config: %s", config_file)
47 config = my_lib.config.load(config_file)
49 target_list = [
50 {
51 "name": name,
52 "liveness_file": pathlib.Path(config["liveness"]["file"][name]),
53 "interval": 10,
54 }
55 for name in ["scheduler", "valve_control", "flow_notify"]
56 ]
58 if check_liveness(target_list, port):
59 logging.info("OK.")
60 sys.exit(0)
61 else:
62 sys.exit(-1)