48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from typing import Dict
|
|
|
|
def health_check() -> Dict[str, str]:
|
|
"""
|
|
Health check function to check if the service is running.
|
|
|
|
Returns:
|
|
A dictionary with a 'status' key indicating the service status.
|
|
"""
|
|
return {"status": "OK"}
|
|
|
|
def is_service_healthy(response: Dict[str, str]) -> bool:
|
|
"""
|
|
Check if the service is healthy based on the health check response.
|
|
|
|
Args:
|
|
response: The response dictionary from the health check.
|
|
|
|
Returns:
|
|
True if the service is healthy, False otherwise.
|
|
"""
|
|
return response.get("status") == "OK"
|
|
|
|
def get_service_status() -> str:
|
|
"""
|
|
Get the service status as a string.
|
|
|
|
Returns:
|
|
A string representing the service status.
|
|
"""
|
|
response = health_check()
|
|
if is_service_healthy(response):
|
|
return "Service is running"
|
|
else:
|
|
return "Service is not running"
|
|
|
|
def format_health_check_response(response: Dict[str, str]) -> str:
|
|
"""
|
|
Format the health check response as a string.
|
|
|
|
Args:
|
|
response: The response dictionary from the health check.
|
|
|
|
Returns:
|
|
A formatted string representing the health check response.
|
|
"""
|
|
status = response.get("status", "Unknown")
|
|
return f"Service status: {status}" |