Coverage for src / healthz.py: 0%
4 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-13 00:10 +0900
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-13 00:10 +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
20if __name__ == "__main__":
21 import docopt
22 import my_lib.config
23 import my_lib.logger
25 # docstringを使用(__doc__がNoneでないことを確認)
26 assert __doc__ is not None, "Module docstring is required" # noqa: S101
27 args = docopt.docopt(__doc__)
29 config_file = args["-c"]
30 port = args["-p"]
31 debug_mode = args["-D"]
33 my_lib.logger.init("hems.rasp-water", level=logging.DEBUG if debug_mode else logging.INFO)
35 config = my_lib.config.load(config_file)
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 ]
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 )
52 if not failed_targets:
53 logging.info("OK.")
54 sys.exit(0)
55 else:
56 sys.exit(-1)