Skip to content

Commit

Permalink
Added healthcheck endpoint to API (#525)
Browse files Browse the repository at this point in the history
* Added healthcheck endpoint to API

* Imported app version from settings and upgraded node in jest test action

* Updated setup-node

* Updated node-version
  • Loading branch information
bzzz-coding authored Apr 19, 2024
1 parent d087c99 commit 379ea51
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/jest-react-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
- name: Install modules
run: |
cd frontend
Expand Down
1 change: 1 addition & 0 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@

WSGI_APPLICATION = "config.wsgi.application"

VERSION = '1.0.0'

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
Expand Down
2 changes: 1 addition & 1 deletion backend/server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
urlpatterns = [
path("", include(router.urls)),
path("", include("rest_framework.urls")),
path("healthcheck", views.Healthcheck.as_view()),
path('healthcheck/', views.Healthcheck.as_view(), name='healthcheck'),
path(
"schema",
get_schema_view(
Expand Down
15 changes: 13 additions & 2 deletions backend/server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from rest_framework.views import APIView
from server.models import Opportunity
from server.serializers import OpportunitySerializer, UserSerializer

import time
from django.conf import settings

class OpportunitiesViewSet(viewsets.ModelViewSet):
"""
Expand All @@ -28,5 +29,15 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):


class Healthcheck(APIView):
start_time = time.time()

def get(self, request):
return Response({"message": "healthcheck"})
uptime_seconds = time.time() - self.start_time
uptime_hours = uptime_seconds / 3600

return Response({
"message": "healthcheck",
"uptime": f"{uptime_hours:.2f} hours",
# "uptime": f"{uptime_seconds:.1f} seconds",
"version": settings.VERSION
})

0 comments on commit 379ea51

Please sign in to comment.