Skip to content

Commit

Permalink
Closes #161
Browse files Browse the repository at this point in the history
  • Loading branch information
dougppaz committed Jul 10, 2018
1 parent eb555e3 commit 423f4fa
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions bothub/health/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

CHECK_ACCESSIBLE_API_URL = '/api/repositories/'


def check_database_connection(**kwargs):
from django.db import connections
from django.db.utils import OperationalError
db_conn = connections['default']
if not db_conn:
return False
try:
db_conn.cursor()
return True
except OperationalError as e:
if len(connections.all()) is 0:
return False
logger.info('found {} database connection'.format(len(connections.all())))
for i, conn in enumerate(connections.all(), 1):
db_conn = connections['default']
try:
db_conn.cursor()
logger.info('#{} db connection OKAY'.format(i))
except OperationalError as e:
logger.warning('#{} db connection ERROR'.format(i))
return False
return True


def check_accessible_api(request, **kwargs):
Expand Down

0 comments on commit 423f4fa

Please sign in to comment.