diff --git a/changelog.d/+disable-redis-setting.added.md b/changelog.d/+disable-redis-setting.added.md new file mode 100644 index 000000000..227ca63d9 --- /dev/null +++ b/changelog.d/+disable-redis-setting.added.md @@ -0,0 +1,2 @@ +Added ARGUS_DISABLE_REDIS setting as an environment variable to disable redis during development +and testing \ No newline at end of file diff --git a/src/argus/site/settings/base.py b/src/argus/site/settings/base.py index 087ac0674..12d29fea2 100644 --- a/src/argus/site/settings/base.py +++ b/src/argus/site/settings/base.py @@ -217,16 +217,27 @@ ASGI_APPLICATION = "argus.ws.asgi.application" +# Disable using Redis in Channels and fall back to an InMemoryChannel +# WARNING: This should only ever be used during development/testing and never +# in production. To enforce this it is only ever activated when DEBUG is also set # fmt: off -_REDIS = urlsplit("//" + get_str_env("ARGUS_REDIS_SERVER", "127.0.0.1:6379")) -CHANNEL_LAYERS = { - "default": { - "BACKEND": "channels_redis.core.RedisChannelLayer", - "CONFIG": { - "hosts": [(_REDIS.hostname, _REDIS.port or 6379)], +ARGUS_DISABLE_REDIS = get_bool_env("ARGUS_DISABLE_REDIS", False) +if ARGUS_DISABLE_REDIS and DEBUG: + CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels.layers.InMemoryChannelLayer", }, - }, -} + } +else: + _REDIS = urlsplit("//" + get_str_env("ARGUS_REDIS_SERVER", "127.0.0.1:6379")) + CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels_redis.core.RedisChannelLayer", + "CONFIG": { + "hosts": [(_REDIS.hostname, _REDIS.port or 6379)], + }, + }, + } # fmt: on # Project specific settings