Skip to content

Commit

Permalink
fix: log health check
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 29, 2024
1 parent 88095c5 commit 07875b5
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions codeforlife/views/health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Created on 14/11/2024 at 16:31:56(+00:00).
"""

import json
import logging
import typing as t
from dataclasses import dataclass
from datetime import datetime
Expand Down Expand Up @@ -83,23 +85,30 @@ def get(self, request: Request):
"""Return a health check for the current service."""
health_check = self.get_health_check(request)

data = {
"appId": settings.APP_ID,
"healthStatus": health_check.health_status,
"lastCheckedTimestamp": datetime.now().isoformat(),
"additionalInformation": health_check.additional_info,
"startupTimestamp": self.startup_timestamp,
"appVersion": settings.APP_VERSION,
"details": [
{
"name": detail.name,
"description": detail.description,
"health": detail.health,
}
for detail in (health_check.details or [])
],
}

if health_check.health_status != "healthy":
data_str = json.dumps(data)
print(f"(print) health check: {data_str}")
logging.warning("(log) health check: %s", data_str)

return Response(
data={
"appId": settings.APP_ID,
"healthStatus": health_check.health_status,
"lastCheckedTimestamp": datetime.now().isoformat(),
"additionalInformation": health_check.additional_info,
"startupTimestamp": self.startup_timestamp,
"appVersion": settings.APP_VERSION,
"details": [
{
"name": detail.name,
"description": detail.description,
"health": detail.health,
}
for detail in (health_check.details or [])
],
},
data,
status={
# The app is running normally.
"healthy": status.HTTP_200_OK,
Expand Down

0 comments on commit 07875b5

Please sign in to comment.