From 0c2437899853ce639779e0e37cc53fe7e4c542ee Mon Sep 17 00:00:00 2001 From: Pelle Koster Date: Tue, 23 Apr 2024 11:50:05 +0200 Subject: [PATCH 1/3] Allow disabling redis --- src/argus/site/settings/base.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/argus/site/settings/base.py b/src/argus/site/settings/base.py index 087ac0674..8b497de30 100644 --- a/src/argus/site/settings/base.py +++ b/src/argus/site/settings/base.py @@ -218,14 +218,22 @@ ASGI_APPLICATION = "argus.ws.asgi.application" # fmt: off -_REDIS = urlsplit("//" + get_str_env("ARGUS_REDIS_SERVER", "127.0.0.1:6379")) -CHANNEL_LAYERS = { +ARGUS_DISABLE_REDIS = get_bool_env("ARGUS_DISABLE_REDIS", False) +if ARGUS_DISABLE_REDIS: + CHANNEL_LAYERS = { "default": { - "BACKEND": "channels_redis.core.RedisChannelLayer", - "CONFIG": { - "hosts": [(_REDIS.hostname, _REDIS.port or 6379)], + "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 From ab91dc40d33f3d6f9c4804f81e4a4982b878a2d5 Mon Sep 17 00:00:00 2001 From: Pelle Koster Date: Tue, 23 Apr 2024 11:55:11 +0200 Subject: [PATCH 2/3] formatting --- src/argus/site/settings/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/argus/site/settings/base.py b/src/argus/site/settings/base.py index 8b497de30..1e5675d0d 100644 --- a/src/argus/site/settings/base.py +++ b/src/argus/site/settings/base.py @@ -221,10 +221,10 @@ ARGUS_DISABLE_REDIS = get_bool_env("ARGUS_DISABLE_REDIS", False) if ARGUS_DISABLE_REDIS: CHANNEL_LAYERS = { - "default": { - "BACKEND": "channels.layers.InMemoryChannelLayer" + "default": { + "BACKEND": "channels.layers.InMemoryChannelLayer", + }, } -} else: _REDIS = urlsplit("//" + get_str_env("ARGUS_REDIS_SERVER", "127.0.0.1:6379")) CHANNEL_LAYERS = { @@ -234,7 +234,7 @@ "hosts": [(_REDIS.hostname, _REDIS.port or 6379)], }, }, -} + } # fmt: on # Project specific settings From 8809dcc77279ac87e969f164d952e35261e845d2 Mon Sep 17 00:00:00 2001 From: Pelle Koster Date: Thu, 25 Apr 2024 15:41:53 +0200 Subject: [PATCH 3/3] allow disable redis only when debug is true --- changelog.d/+disable-redis-setting.added.md | 2 ++ src/argus/site/settings/base.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelog.d/+disable-redis-setting.added.md 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 1e5675d0d..12d29fea2 100644 --- a/src/argus/site/settings/base.py +++ b/src/argus/site/settings/base.py @@ -217,9 +217,12 @@ 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 ARGUS_DISABLE_REDIS = get_bool_env("ARGUS_DISABLE_REDIS", False) -if ARGUS_DISABLE_REDIS: +if ARGUS_DISABLE_REDIS and DEBUG: CHANNEL_LAYERS = { "default": { "BACKEND": "channels.layers.InMemoryChannelLayer",