-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from Ilhasoft/develop
Version 1.13.4
- Loading branch information
Showing
8 changed files
with
181 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ whitenoise = "*" | |
[dev-packages] | ||
"flake8" = "*" | ||
coverage = "*" | ||
ipython = "*" | ||
|
||
[requires] | ||
python_version = "3.6" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
import logging | ||
|
||
from rest_framework import status | ||
|
||
|
||
logger = logging.getLogger('bothub.health.checks') | ||
|
||
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): | ||
try: | ||
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): | ||
import requests | ||
HTTP_HOST = request.META.get('HTTP_HOST') | ||
repositories_url = 'http://{}/api/repositories/'.format(HTTP_HOST) | ||
request = requests.get(repositories_url) | ||
try: | ||
request.raise_for_status() | ||
from django.test import Client | ||
logger.info('making request to {}'.format(CHECK_ACCESSIBLE_API_URL)) | ||
client = Client() | ||
response = client.get(CHECK_ACCESSIBLE_API_URL) | ||
logger.info('{} status code: {}'.format( | ||
CHECK_ACCESSIBLE_API_URL, | ||
response.status_code)) | ||
if response.status_code is status.HTTP_200_OK: | ||
return True | ||
except requests.HTTPError as e: | ||
return False | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters