Add helper functions for Dict
This commit is contained in:
parent
56bb49a038
commit
2f3dd5fb51
53
helpers/dict_helpers.py
Normal file
53
helpers/dict_helpers.py
Normal file
@ -0,0 +1,53 @@
|
||||
from typing import Dict
|
||||
|
||||
def get_health_status() -> Dict[str, str]:
|
||||
"""
|
||||
Get the health status of the service.
|
||||
|
||||
Returns:
|
||||
A dictionary containing the health status.
|
||||
"""
|
||||
return {"status": "OK"}
|
||||
|
||||
def is_service_healthy() -> bool:
|
||||
"""
|
||||
Check if the service is healthy.
|
||||
|
||||
Returns:
|
||||
True if the service is healthy, False otherwise.
|
||||
"""
|
||||
# Add any additional checks for service health here
|
||||
return True
|
||||
|
||||
def format_health_response(status: Dict[str, str]) -> Dict[str, str]:
|
||||
"""
|
||||
Format the health response.
|
||||
|
||||
Args:
|
||||
status: The health status dictionary.
|
||||
|
||||
Returns:
|
||||
The formatted health response dictionary.
|
||||
"""
|
||||
return {
|
||||
"service": "My Service",
|
||||
"status": status["status"],
|
||||
"message": "Service is running properly."
|
||||
}
|
||||
|
||||
def get_formatted_health_response() -> Dict[str, str]:
|
||||
"""
|
||||
Get the formatted health response.
|
||||
|
||||
Returns:
|
||||
The formatted health response dictionary.
|
||||
"""
|
||||
status = get_health_status()
|
||||
if is_service_healthy():
|
||||
return format_health_response(status)
|
||||
else:
|
||||
return {
|
||||
"service": "My Service",
|
||||
"status": "UNHEALTHY",
|
||||
"message": "Service is not running properly."
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user