Files
notifications-admin/app/utils/api_health.py

23 lines
593 B
Python
Raw Normal View History

2025-04-22 12:09:00 -07:00
import logging
import os
2025-04-22 12:09:00 -07:00
import requests
from requests.exceptions import RequestException
2025-04-21 16:26:07 -07:00
logger = logging.getLogger(__name__)
2025-06-06 11:22:29 -07:00
def is_api_down():
2025-04-21 16:26:07 -07:00
api_base_url = os.getenv("API_HOST_NAME")
try:
2025-06-09 09:17:12 -07:00
response = requests.get(api_base_url, timeout=2)
2025-04-21 16:26:07 -07:00
is_down = response.status_code != 200
if is_down:
2025-05-02 10:43:07 -04:00
logger.warning(
f"API responded with status {response.status_code} at {api_base_url}"
)
2025-04-21 16:26:07 -07:00
return is_down
except RequestException as e:
logger.error(f"API down when loading homepage {e}")
return True