Skip to content

Commit

Permalink
feat: add health-check
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Dec 4, 2024
1 parent fe3ed1b commit bcaf5c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion manage_content_service/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from manage_content_service.celery_app import app as celery_app
import time

__all__ = ("celery_app",)
__all__ = ("celery_app",)
start_time = time.time()
23 changes: 23 additions & 0 deletions manage_content_service/health_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# views.py
from django.http import JsonResponse
import time
from . import start_time


def health_check(request):
"""
Health check for monitoring services.
"""
# Here you can perform additional checks like database, cache, etc.

# Assuming start_time is recorded when the app starts
uptime = time.time() - start_time
status = {
"status": "ok",
"uptime": uptime,
"response_time": 0, # You can calculate the response time here
"apdex": 0, # You can add Apdex calculation here
"last_check": time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(uptime)),
}

return JsonResponse(status)
2 changes: 2 additions & 0 deletions manage_content_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from manage_content_service.health_check import health_check
from manage_content_service.settings.base import get_environment_var
import sentry_sdk

Expand All @@ -29,6 +30,7 @@
)

urlpatterns = [
path('health-check/', health_check, name='health_check'),
path('api/admin/', admin.site.urls),
path('api/auth/', include(('apps.accounts.urls', 'accounts'), namespace='accounts')),
path('api/fsm/', include('apps.fsm.urls')),
Expand Down

0 comments on commit bcaf5c6

Please sign in to comment.