dynamic CELERY_BROKER_URL property in settings

This commit is contained in:
msramalho
2025-02-11 21:33:02 +00:00
parent 0eef5aa9ce
commit 0834f55520
2 changed files with 7 additions and 1 deletions

View File

@@ -33,7 +33,11 @@ class Settings(BaseSettings):
# redis
REDIS_PASSWORD: str = ""
CELERY_BROKER_URL: str = "redis://localhost:6379"
@property
def CELERY_BROKER_URL(self)-> str:
if self.REDIS_PASSWORD:
return f"redis://:{self.REDIS_PASSWORD}@localhost:6379"
return "redis://localhost:6379"
REDIS_EXCEPTIONS_CHANNEL: str = "exceptions-channel"
# observability

View File

@@ -15,4 +15,6 @@ def get_celery(name:str="") -> Celery:
def get_redis() -> redis.Redis:
from loguru import logger
logger.debug(get_settings().CELERY_BROKER_URL)
return redis.Redis.from_url(get_settings().CELERY_BROKER_URL)