Coverage for src/healthz.py: 85%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2024-11-24 19:24 +0900

1#!/usr/bin/env python3 

2""" 

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

4 

5Usage: 

6 healthz.py [-c CONFIG] [-d] 

7 

8Options: 

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

10 -d : デバッグモードで動作します. 

11""" 

12 

13import logging 

14import pathlib 

15import sys 

16 

17import my_lib.healthz 

18 

19 

20def check_liveness(target_list): 

21 for target in target_list: 

22 if not my_lib.healthz.check_liveness(target["name"], target["liveness_file"], target["interval"]): 22 ↛ 23line 22 didn't jump to line 23 because the condition on line 22 was never true

23 return False 

24 

25 return True 

26 

27 

28###################################################################### 

29if __name__ == "__main__": 

30 import docopt 

31 import my_lib.config 

32 import my_lib.logger 

33 

34 args = docopt.docopt(__doc__) 

35 

36 config_file = args["-c"] 

37 debug_mode = args["-d"] 

38 

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

40 

41 logging.info("Using config config: %s", config_file) 

42 config = my_lib.config.load(config_file) 

43 

44 target_list = [ 

45 { 

46 "name": name, 

47 "liveness_file": pathlib.Path(config["liveness"]["file"][name]), 

48 "interval": config["liveness"]["interval_sec"], 

49 } 

50 for name in ["scheduler"] 

51 ] 

52 

53 if check_liveness(target_list): 

54 logging.info("OK.") 

55 sys.exit(0) 

56 else: 

57 sys.exit(-1)