diff --git a/ibms_project/middleware.py b/ibms_project/middleware.py index 165414f..9ef1ae6 100644 --- a/ibms_project/middleware.py +++ b/ibms_project/middleware.py @@ -1,13 +1,12 @@ -from django.db import connections -from django.http import HttpResponse, HttpResponseServerError import logging +from django.db import connections +from django.http import HttpResponse, HttpResponseServerError LOGGER = logging.getLogger("ibms") class HealthCheckMiddleware(object): - def __init__(self, get_response): self.get_response = get_response @@ -20,8 +19,7 @@ def __call__(self, request): return self.get_response(request) def liveness(self, request): - """Returns that the server is alive. - """ + """Returns that the server is alive.""" return HttpResponse("OK") def readiness(self, request): @@ -33,6 +31,7 @@ def readiness(self, request): cursor = connections["default"].cursor() cursor.execute("SELECT 1;") row = cursor.fetchone() + cursor.close() if row is None: return HttpResponseServerError("Database: invalid response") except Exception as e: