From a4435fdd60b3a4272190c4ac8e55f590a8bce8c2 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 23 Dec 2024 22:29:52 +0700 Subject: [PATCH] use REDIS_CON for redis connection string --- CONTRIBUTING.md | 4 ++-- README.md | 3 +-- backend/common/src/env_settings.py | 6 ++---- backend/common/src/ta_redis.py | 6 ++---- backend/config/management/commands/ta_envcheck.py | 4 +++- backend/task/celery.py | 7 ++----- docker-compose.yml | 2 +- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 23a896b7..d27660ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -153,9 +153,9 @@ TA_HOST="localhost" TA_USERNAME=tubearchivist TA_PASSWORD=verysecret TA_MEDIA_DIR="static/volume/media" -TA_CACHE_DIR="static/volume/cache" +TA_CACHE_DIR="static" TA_APP_DIR="." -REDIS_HOST=localhost +REDIS_CON=redis://localhost:6379 ES_URL="http://localhost:9200" ELASTIC_PASSWORD=verysecret TZ=America/New_York diff --git a/README.md b/README.md index c123c019..ba85de13 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Take a look at the example [docker-compose.yml](https://github.com/tubearchivist | TA_USERNAME | Initial username when logging into TA | Required | | TA_PASSWORD | Initial password when logging into TA | Required | | ELASTIC_PASSWORD | Password for ElasticSearch | Required | -| REDIS_HOST | Hostname for Redis | Required | +| REDIS_CON | Connection string to Redis | Required | | TZ | Set your timezone for the scheduler | Required | | TA_PORT | Overwrite Nginx port | Optional | | TA_BACKEND_PORT | Overwrite container internal backend server port | Optional | @@ -67,7 +67,6 @@ Take a look at the example [docker-compose.yml](https://github.com/tubearchivist | HOST_GID | Allow TA to own the video files instead of container user | Optional | | HOST_UID | Allow TA to own the video files instead of container user | Optional | | ELASTIC_USER | Change the default ElasticSearch user | Optional | -| REDIS_PORT | Port that Redis runs on | Optional | | TA_LDAP | Configure TA to use LDAP Authentication | [Read more](https://docs.tubearchivist.com/configuration/ldap/) | | ENABLE_CAST | Enable casting support | [Read more](https://docs.tubearchivist.com/configuration/cast/) | | DJANGO_DEBUG | Return additional error messages, for debug only | | diff --git a/backend/common/src/env_settings.py b/backend/common/src/env_settings.py index aff67bcd..5969a06f 100644 --- a/backend/common/src/env_settings.py +++ b/backend/common/src/env_settings.py @@ -37,8 +37,7 @@ class EnvironmentSettings: CACHE_DIR: str = str(environ.get("TA_CACHE_DIR", "/cache")) # Redis - REDIS_HOST: str = str(environ.get("REDIS_HOST")) - REDIS_PORT: int = int(environ.get("REDIS_PORT", 6379)) + REDIS_CON: str = str(environ.get("REDIS_CON")) REDIS_NAME_SPACE: str = str(environ.get("REDIS_NAME_SPACE", "ta:")) # ElasticSearch @@ -93,8 +92,7 @@ class EnvironmentSettings: """debug redis conf paths""" print( f""" - REDIS_HOST: {self.REDIS_HOST} - REDIS_PORT: {self.REDIS_PORT} + REDIS_CON: {self.REDIS_CON} REDIS_NAME_SPACE: {self.REDIS_NAME_SPACE}""" ) diff --git a/backend/common/src/ta_redis.py b/backend/common/src/ta_redis.py index 4390c326..e4296d9f 100644 --- a/backend/common/src/ta_redis.py +++ b/backend/common/src/ta_redis.py @@ -17,10 +17,8 @@ class RedisBase: NAME_SPACE: str = EnvironmentSettings.REDIS_NAME_SPACE def __init__(self): - self.conn = redis.Redis( - host=EnvironmentSettings.REDIS_HOST, - port=EnvironmentSettings.REDIS_PORT, - decode_responses=True, + self.conn = redis.from_url( + url=EnvironmentSettings.REDIS_CON, decode_responses=True ) diff --git a/backend/config/management/commands/ta_envcheck.py b/backend/config/management/commands/ta_envcheck.py index 8918777f..bdc591b5 100644 --- a/backend/config/management/commands/ta_envcheck.py +++ b/backend/config/management/commands/ta_envcheck.py @@ -62,7 +62,9 @@ EXPECTED_ENV_VARS = [ "TA_HOST", ] UNEXPECTED_ENV_VARS = { - "TA_UWSGI_PORT": "Has been replaced with 'TA_BACKEND_PORT'" + "TA_UWSGI_PORT": "Has been replaced with 'TA_BACKEND_PORT'", + "REDIS_HOST": "Has been replaced with 'REDIS_CON' connection string", + "REDIS_PORT": "Has been consolidated in 'REDIS_CON' connection string", } INST = "https://github.com/tubearchivist/tubearchivist#installing-and-updating" NGINX = "/etc/nginx/sites-available/default" diff --git a/backend/task/celery.py b/backend/task/celery.py index 28cdbf72..b7af1ba0 100644 --- a/backend/task/celery.py +++ b/backend/task/celery.py @@ -5,14 +5,11 @@ import os from celery import Celery from common.src.env_settings import EnvironmentSettings -REDIS_HOST = EnvironmentSettings.REDIS_HOST -REDIS_PORT = EnvironmentSettings.REDIS_PORT - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") app = Celery( "tasks", - broker=f"redis://{REDIS_HOST}:{REDIS_PORT}", - backend=f"redis://{REDIS_HOST}:{REDIS_PORT}", + broker=EnvironmentSettings.REDIS_CON, + backend=EnvironmentSettings.REDIS_CON, result_extended=True, ) app.config_from_object( diff --git a/docker-compose.yml b/docker-compose.yml index bbd11302..00ece157 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - cache:/cache environment: - ES_URL=http://archivist-es:9200 # needs protocol e.g. http and port - - REDIS_HOST=archivist-redis # don't add protocol + - REDIS_CON=redis://archivist-redis:6379 - HOST_UID=1000 - HOST_GID=1000 - TA_HOST=tubearchivist.local # set your host name