Skip to content

Commit

Permalink
Merge c5e6aca into 97a86b5
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Paz committed Jul 10, 2018
2 parents 97a86b5 + c5e6aca commit 86d7a04
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 29 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ whitenoise = "*"
[dev-packages]
"flake8" = "*"
coverage = "*"
ipython = "*"

[requires]
python_version = "3.6"
129 changes: 122 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 30 additions & 15 deletions bothub/health/checks.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
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):
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):
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
19 changes: 19 additions & 0 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dj_database_url

from decouple import config
from django.utils.log import DEFAULT_LOGGING


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -204,3 +205,21 @@
'CSRF_COOKIE_SECURE',
default=False,
cast=bool)


# Logging

LOGGING = DEFAULT_LOGGING
LOGGING['formatters']['bothub.health'] = {
'format': '[bothub.health] {message}',
'style': '{',
}
LOGGING['handlers']['bothub.health'] = {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'bothub.health',
}
LOGGING['loggers']['bothub.health.checks'] = {
'handlers': ['bothub.health'],
'level': 'DEBUG',
}
10 changes: 5 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ services:
ports:
- 80:80
environment:
- SECRET_KEY
- SECRET_KEY=SK
- DEBUG
- ALLOWED_HOSTS
- DEFAULT_DATABASE
- LANGUAGE_CODE
- TIME_ZONE
- EMAIL_HOST
- EMAIL_HOST=
- EMAIL_PORT
- DEFAULT_FROM_EMAIL
- SERVER_EMAIL
Expand All @@ -26,8 +26,8 @@ services:
- ADMINS
- CSRF_COOKIE_DOMAIN
- CSRF_COOKIE_SECURE
- BOTHUB_WEBAPP_BASE_URL
- BOTHUB_NLP_BASE_URL
- BOTHUB_WEBAPP_BASE_URL=http://localhost/
- BOTHUB_NLP_BASE_URL=http://localhost:2657/
- WEBAPP_REPO=https://github.com/Ilhasoft/bothub-webapp
- WEBAPP_BRANCH=master
- API_BASE_URL
- API_BASE_URL=/api
5 changes: 3 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ cd $WORKDIR
python manage.py migrate
python manage.py collectstatic --noinput

gunicorn -e DJANGO_SETTINGS_MODULE=bothub.settings -b unix:/tmp/bothub.sock -D bothub.wsgi
gunicorn -e DJANGO_SETTINGS_MODULE=bothub.settings -b unix:/tmp/bothub.sock -D bothub.wsgi --log-file /var/log/gunicorn.log --log-level debug --capture-output

mkdir -p /run/nginx/
nginx -g "daemon off;"
nginx
tail -f /var/log/nginx/* /var/log/gunicorn.log

0 comments on commit 86d7a04

Please sign in to comment.