mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 21:39:49 +00:00
add health API endpoint, #887
This commit is contained in:
@@ -1,11 +0,0 @@
|
|||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
|
|
||||||
class HealthCheckMiddleware:
|
|
||||||
def __init__(self, get_response):
|
|
||||||
self.get_response = get_response
|
|
||||||
|
|
||||||
def __call__(self, request):
|
|
||||||
if request.path == "/health":
|
|
||||||
return HttpResponse("ok")
|
|
||||||
return self.get_response(request)
|
|
||||||
@@ -25,4 +25,9 @@ urlpatterns = [
|
|||||||
views.NotificationView.as_view(),
|
views.NotificationView.as_view(),
|
||||||
name="api-notification",
|
name="api-notification",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"health/",
|
||||||
|
views.HealthCheck.as_view(),
|
||||||
|
name="api-health",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from common.src.watched import WatchState
|
|||||||
from common.views_base import AdminOnly, ApiBaseView
|
from common.views_base import AdminOnly, ApiBaseView
|
||||||
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
from task.tasks import check_reindex
|
from task.tasks import check_reindex
|
||||||
|
|
||||||
|
|
||||||
@@ -199,3 +200,11 @@ class NotificationView(ApiBaseView):
|
|||||||
response_serializer = NotificationSerializer(notifications, many=True)
|
response_serializer = NotificationSerializer(notifications, many=True)
|
||||||
|
|
||||||
return Response(response_serializer.data)
|
return Response(response_serializer.data)
|
||||||
|
|
||||||
|
|
||||||
|
class HealthCheck(APIView):
|
||||||
|
"""health check view, no auth needed"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""health check, no auth needed"""
|
||||||
|
return Response("OK", status=200)
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ MIDDLEWARE = [
|
|||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
"common.src.health.HealthCheckMiddleware",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = "config.urls"
|
ROOT_URLCONF = "config.urls"
|
||||||
|
|||||||
Reference in New Issue
Block a user