Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions actnow/health.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from django.db import OperationalError, connections
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny
from rest_framework.request import Request
from rest_framework.response import Response

from .petitions.models import Petition


@api_view(["GET"])
def health_check(request):
@permission_classes([AllowAny])
def health_check(request: Request) -> Response:
"""Meta view to check the status of core services."""
data = {"status": "healthy", "detail": "server and core services available"}
try:
Petition.objects.count()
return Response(status=status.HTTP_200_OK)
except Exception:
return Response(status=status.HTTP_503_SERVICE_UNAVAILABLE)
connections["default"].cursor()
except OperationalError:
data["status"] = "unhealthy"
data["detail"] = "unable to connect to database server"
return Response(data=data, status=status.HTTP_503_SERVICE_UNAVAILABLE)
return Response(data=data, status=status.HTTP_200_OK)
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
db:
image: postgres:13.3
Expand Down