This will remove imports from __future__ that are no longer needed. https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
32 lines
912 B
Python
32 lines
912 B
Python
"""
|
|
Views for verifying the health (heartbeat) of the app.
|
|
"""
|
|
|
|
|
|
import six
|
|
|
|
from util.json_request import JsonResponse
|
|
|
|
from .runchecks import runchecks
|
|
|
|
|
|
def heartbeat(request):
|
|
"""
|
|
Simple view that a loadbalancer can check to verify that the app is up. Returns a json doc
|
|
of service id: status or message. If the status for any service is anything other than True,
|
|
it returns HTTP code 503 (Service Unavailable); otherwise, it returns 200.
|
|
"""
|
|
check_results = {}
|
|
try:
|
|
check_results = runchecks('extended' in request.GET)
|
|
|
|
status_code = 200 # Default to OK
|
|
for check in check_results:
|
|
if not check_results[check]['status']:
|
|
status_code = 503 # 503 on any failure
|
|
except Exception as e:
|
|
status_code = 503
|
|
check_results = {'error': six.text_type(e)}
|
|
|
|
return JsonResponse(check_results, status=status_code)
|