Skip to content

Commit

Permalink
health
Browse files Browse the repository at this point in the history
  • Loading branch information
sritanmotati committed Feb 5, 2025
1 parent 524282d commit 7627e84
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/ohq/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SemesterViewSet,
TagViewSet,
UserView,
HealthView,
)


Expand All @@ -45,6 +46,7 @@
realtime_router.register(AnnouncementViewSet)

additional_urls = [
path("health/", HealthView.as_view(), name="health"),
path("accounts/me/", UserView.as_view(), name="me"),
path("accounts/me/resend/", ResendNotificationView.as_view(), name="resend"),
path("courses/<slug:course_pk>/mass-invite/", MassInviteView.as_view(), name="mass-invite"),
Expand Down
21 changes: 21 additions & 0 deletions backend/ohq/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Subquery,
When,
)
from django.views.generic import View
from django.http import HttpResponseBadRequest, JsonResponse
from django.utils import timezone
from django.utils.crypto import get_random_string
Expand All @@ -32,6 +33,7 @@
from rest_framework.views import APIView
from rest_live.mixins import RealtimeMixin
from schedule.models import Event, EventRelationManager, Occurrence
from http import HTTPStatus

from ohq.filters import CourseStatisticFilter, QuestionSearchFilter, QueueStatisticFilter
from ohq.invite import parse_and_send_invites
Expand Down Expand Up @@ -775,3 +777,22 @@ def list(self, request, *args, **kwargs):

def get_queryset(self):
return Occurrence.objects.filter(pk=self.kwargs["pk"])
class HealthView(View):
def get(self, request):
"""
Health check endpoint to confirm the backend is running.
---
summary: Health Check
responses:
"200":
content:
application/json:
schema:
type: object
properties:
message:
type: string
enum: ["OK"]
---
"""
return JsonResponse({"message": "OK"}, status=HTTPStatus.OK)
9 changes: 9 additions & 0 deletions backend/tests/ohq/test_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.test import TestCase
from django.urls import reverse

class HealthTestCase(TestCase):
def test_health(self):
url = reverse("health")
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data, {"message": "OK"})
24 changes: 24 additions & 0 deletions frontend/pages/health.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { GetServerSideProps } from 'next';

const HealthPage = () => {
return <div>OK</div>;
};

export const getServerSideProps: GetServerSideProps = async ({ req }) => {
const userAgent = req.headers['user-agent'] || '';

if (userAgent !== 'service-status') {
return {
redirect: {
destination: '/',
permanent: false,
},
};
}

return {
props: {},
};
};

export default HealthPage;

0 comments on commit 7627e84

Please sign in to comment.