Skip to content

Commit 3c4ec8b

Browse files
authored
fix: update MongoDB health check to ensure compatibility with AWS task health checks
1 parent 78212a0 commit 3c4ec8b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

backend/backend/apis/bwwc.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,16 @@ def backup(req: HttpRequest) -> HttpResponse:
305305

306306

307307
@csrf_exempt
308-
def mongo_health(req: HttpRequest) -> HttpResponse:
309-
if req.method == "GET":
310-
if not engine.is_mongodb_running():
311-
return HttpResponseBadRequest("MongoDB is down")
308+
def mongo_health(req: HttpRequest) -> JsonResponse:
309+
if req.method != "GET":
310+
return JsonResponse({"status": "Method Not Allowed"}, status=405)
311+
try:
312+
if engine.is_mongodb_running():
313+
return JsonResponse({"status": "ok"}, status=200)
312314
else:
313-
return HttpResponse("MongoDB is up")
314-
else:
315-
return HttpResponseBadRequest("Invalid request method")
315+
return JsonResponse({"status": "error", "message": "MongoDB is down"}, status=503)
316+
except Exception as e:
317+
return JsonResponse({"status": "error", "message": str(e)}, status=503)
316318

317319

318320
def get_urlpatterns():

0 commit comments

Comments
 (0)