Add Health Check endpoint (#392)

* add simple health endpoint

* add curl and healthcheck to dockerfile

* convert to view

* add simple test

* Add unhealthy test

* Cleanup

* check for LD_SERVER_PORT env var in healthcheck def

* Revert changes to middlewares.py

Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
McKenna Jones
2023-01-20 14:26:58 -07:00
committed by GitHub
parent 894625aa25
commit da99b8b034
5 changed files with 64 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
from .bookmarks import *
from .settings import *
from .toasts import *
from .health import health

20
bookmarks/views/health.py Normal file
View File

@@ -0,0 +1,20 @@
from django.db import connections
from django.http import JsonResponse
from bookmarks.views.settings import app_version
def health(request):
code = 200
response = {
'version': app_version,
'status': 'healthy'
}
try:
connections['default'].ensure_connection()
except Exception:
response['status'] = 'unhealthy'
code = 500
return JsonResponse(response, status=code)