forked from CGM_Public/pretix_original
Healthcheck: Check redis and cache
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from django.conf import settings
|
||||||
|
from django.core import cache
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from ..models import User
|
from ..models import User
|
||||||
@@ -6,4 +8,18 @@ from ..models import User
|
|||||||
def healthcheck(request):
|
def healthcheck(request):
|
||||||
# Perform a simple DB query to see that DB access works
|
# Perform a simple DB query to see that DB access works
|
||||||
User.objects.exists()
|
User.objects.exists()
|
||||||
|
|
||||||
|
# Test if redis access works
|
||||||
|
if settings.HAS_REDIS:
|
||||||
|
import django_redis
|
||||||
|
|
||||||
|
redis = django_redis.get_redis_connection("redis")
|
||||||
|
redis.set("_healthcheck", 1)
|
||||||
|
if not redis.exists("_healthcheck"):
|
||||||
|
return HttpResponse("Redis not available.", status=503)
|
||||||
|
|
||||||
|
cache.cache.set("_healthcheck", "1")
|
||||||
|
if not cache.cache.get("_healthcheck") == "1":
|
||||||
|
return HttpResponse("Cache not available.", status=503)
|
||||||
|
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
|||||||
Reference in New Issue
Block a user