Skip to content

Commit

Permalink
Consistent readiness check.
Browse files Browse the repository at this point in the history
  • Loading branch information
ropable committed Mar 1, 2024
1 parent aeeb38b commit 0cc21bf
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions itassets/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ def readiness(self, request):
"""
try:
from django.db import connections
for name in connections:
cursor = connections[name].cursor()
cursor.execute("SELECT 1;")
row = cursor.fetchone()
if row is None:
return HttpResponseServerError("db: invalid response")
cursor = connections["default"].cursor()
cursor.execute("SELECT 1;")
row = cursor.fetchone()
if row is None:
return HttpResponseServerError("Database: invalid response")
except Exception as e:
LOGGER.exception(e)
return HttpResponseServerError("db: cannot connect to database.")
return HttpResponseServerError("Database: unable to connect")

return HttpResponse("OK")

0 comments on commit 0cc21bf

Please sign in to comment.