File size: 981 Bytes
5a8199e
 
 
 
8980653
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a8199e
 
 
 
 
 
 
 
 
8980653
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os

HEALTH_MODELS = os.getenv("HEALTH_MODELS", "")


def run_healthcheck():
    import os
    import requests
    import sys
    import structlog
    from samgis_core.utilities.session_logger import setup_logging

    log_level = os.getenv("LOG_LEVEL", "INFO")
    url1 = os.getenv("HEALTHCHECK_URL1", "http://localhost:7860/health")
    url2 = os.getenv("HEALTHCHECK_URL2", "http://localhost:7860/health_models")
    setup_logging(log_level=log_level)
    app_logger = structlog.stdlib.get_logger()

    r1 = requests.get(url1)
    app_logger.info(r1.status_code)
    msg = f"status health:{r1.status_code}!"
    if HEALTH_MODELS:
        r2 = requests.get(url2)
        msg += f" status health_models:{r2.status_code}!"
        app_logger.info(msg)
        sys.exit(0) if r1.status_code == 200 and r2.status_code == 200 else sys.exit(1)
    app_logger.info(msg)
    sys.exit(0) if r1.status_code == 200 else sys.exit(1)



if __name__ == "__main__":
    run_healthcheck()