From 9d2ed9dd5956b5e3bb5dfb90f0151a92106e297c Mon Sep 17 00:00:00 2001 From: Mairi Dulaney Date: Mon, 25 Jul 2022 21:31:45 -0700 Subject: [PATCH 1/3] Make redis configurable Signed-off-by: Mairi Dulaney --- radio/utility.py | 18 +++++++++++++----- trunk_player/settings.py | 14 +++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/radio/utility.py b/radio/utility.py index 642a59a..290c722 100644 --- a/radio/utility.py +++ b/radio/utility.py @@ -1,11 +1,19 @@ import redis +from django.conf import settings + class RedisQueue(object): """Simple Queue with Redis Backend""" - def __init__(self, name, namespace='tp', **redis_kwargs): - """The default connection parameters are: host='localhost', port=6379, db=0""" - self.__db= redis.Redis(**redis_kwargs) - self.key = '%s:%s' %(namespace, name) + + def __init__(self, name, namespace="tp", **redis_kwargs): + """The default connection parameters are: host='localhost', port=6379, db=0""" + self.__db = redis.Redis( + host=settings.REDIS_HOST, + port=settings.REDIS_PORT, + db=settings.REDIS_DB, + **redis_kwargs + ) + self.key = "%s:%s" % (namespace, name) def qsize(self): """Return the approximate size of the queue.""" @@ -20,7 +28,7 @@ def put(self, item): self.__db.rpush(self.key, item) def get(self, block=True, timeout=None): - """Remove and return an item from the queue. + """Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available.""" diff --git a/trunk_player/settings.py b/trunk_player/settings.py index eb2c1b5..fdc8be5 100644 --- a/trunk_player/settings.py +++ b/trunk_player/settings.py @@ -165,12 +165,17 @@ MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, "audio_files") +REDIS_HOST = "127.0.0.1" +REDIS_PORT = "6379" +REDIS_URL = "redis://" + REDIS_HOST + ":" + REDIS_PORT +REDIS_DB = "1" + # Channel settings CHANNEL_LAYERS = { "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { - "hosts": [os.environ.get('REDIS_URL', 'redis://127.0.0.1:6379')], + "hosts": [os.environ.get('REDIS_URL', REDIS_URL)], } }, } @@ -178,7 +183,7 @@ CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": "redis://127.0.0.1:6379/1", + "LOCATION": REDIS_URL + "/1", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } @@ -189,7 +194,7 @@ # 0 will disable the limit ANONYMOUS_TIME = int(os.environ.get("ANONYMOUS_TIME", '43200')) # 1 Month (60min * 24hours * 30days) -# This Agency must exist in radio.Agency +# This Agency must exist in radio.Agency RADIO_DEFAULT_UNIT_AGENCY = 0 SITE_ID = 1 @@ -248,7 +253,7 @@ USE_RAW_ID_FIELDS = os.getenv("USE_RAW_ID_FIELDS", 'False').lower() in ('true', '1', 't') -# Load our local settings +# Load our local settings try: LOCAL_SETTINGS except NameError: @@ -257,4 +262,3 @@ except ImportError: pass # print("Failed to open settings_local.py") - From 4cb6fcbccc250787d319f73c8d19e94629d79f00 Mon Sep 17 00:00:00 2001 From: Mairi Dulaney Date: Mon, 25 Jul 2022 21:46:19 -0700 Subject: [PATCH 2/3] Bump channels version Signed-off-by: Mairi Dulaney --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0ca02ee..d22d474 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ autobahn Automat==20.2.0 certifi==2021.5.30 cffi==1.14.6 -channels==3.0.4 +channels==3.0.5 channels-redis==3.3.0 chardet==4.0.0 charset-normalizer==2.0.4 From 1c668be31b4227cf585b585b6fa8bb61e64b1313 Mon Sep 17 00:00:00 2001 From: Mairi Dulaney Date: Wed, 27 Jul 2022 11:20:43 -0700 Subject: [PATCH 3/3] bump asgiref to 3.5.2 Signed-off-by: Mairi Dulaney --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d22d474..94403e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aioredis==1.3.1 -asgiref==3.3.4 +asgiref==3.5.2 async-timeout==3.0.1 attrs==21.2.0 autobahn