Skip to content

Commit

Permalink
Add check to service_health for Enketo Redis main
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Jan 11, 2024
1 parent 0f35d78 commit e4d6ad3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
27 changes: 1 addition & 26 deletions kobo/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding: utf-8
from django.apps import AppConfig
from django.conf import settings
from django.core.checks import register, Tags, Error
from django.core.checks import register, Tags

from kpi.utils.two_database_configuration_checker import \
TwoDatabaseConfigurationChecker
Expand All @@ -19,27 +18,3 @@ def ready(self, *args, **kwargs):


register(TwoDatabaseConfigurationChecker().as_check(), Tags.database)


@register()
def check_enketo_redis_main_url(app_configs, **kwargs):
"""
`ENKETO_REDIS_MAIN_URL` is required to make the app run properly.
"""
errors = []

if not settings.CACHES.get('enketo_redis_main'):
# We need to set `BACKEND` property. Otherwise, this error is shadowed
# by DRF system checks.
settings.CACHES['enketo_redis_main']['BACKEND'] = (
'django.core.cache.backends.dummy.DummyCache'
)
errors.append(
Error(
f'Please set environment variable `ENKETO_REDIS_MAIN_URL`',
hint='Enketo Express Redis main URL is missing.',
obj=settings,
id='kpi.enketo_redis_main.E001',
)
)
return errors
3 changes: 2 additions & 1 deletion kobo/apps/service_health/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests
from django.conf import settings
from django.core.cache import cache
from django.core.cache import cache, caches
from django.http import HttpResponse

from kobo.celery import celery_app
Expand Down Expand Up @@ -75,6 +75,7 @@ def service_health(request):
'Enketo': lambda: requests.get(
settings.ENKETO_INTERNAL_URL, timeout=10
).raise_for_status(),
'Enketo Redis (main)': lambda: caches['enketo_redis_main'].set('a', True, 1),
}

check_results = []
Expand Down
6 changes: 4 additions & 2 deletions kobo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,8 +1301,10 @@ def dj_stripe_request_callback_method():

CACHES = {
# Set CACHE_URL to override
'default': env.cache(default='redis://redis_cache:6380/3'),
'enketo_redis_main': env.cache(var='ENKETO_REDIS_MAIN_URL', default=None)
'default': env.cache_url(default='redis://redis_cache:6380/3'),
'enketo_redis_main': env.cache_url(
'ENKETO_REDIS_MAIN_URL', default='redis://change-me.invalid/0'
),
}

# How long to retain cached responses for kpi endpoints
Expand Down

0 comments on commit e4d6ad3

Please sign in to comment.