Add Redis configuration to celery_config.py (#2227)

This pull request adds Redis configuration to the `celery_config.py`
file. The `CELERY_BROKER_URL` has been replaced with `REDIS_HOST`,
`REDIS_PORT`, and `REDIS_PASS` environment variables to configure the
Redis broker and backend. This change allows for better integration with
Redis in the application.
This commit is contained in:
Stan Girard 2024-02-19 23:51:18 -08:00 committed by GitHub
parent 6db67cc7b6
commit f406afcc45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,9 @@ from celery import Celery
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "")
CELERY_BROKER_QUEUE_NAME = os.getenv("CELERY_BROKER_QUEUE_NAME", "quivr")
REDIS_HOST = os.getenv("REDIS_HOST", "")
REDIS_PORT = os.getenv("REDIS_PORT", "")
REDIS_PASS = os.getenv("REDIS_PASS", "")
celery = Celery(__name__)
@ -25,11 +28,12 @@ if CELERY_BROKER_URL.startswith("sqs"):
broker_transport_options=broker_transport_options,
)
celery.conf.task_default_queue = CELERY_BROKER_QUEUE_NAME
elif CELERY_BROKER_URL.startswith("redis"):
elif REDIS_HOST:
celery = Celery(
__name__,
broker=CELERY_BROKER_URL,
backend=CELERY_BROKER_URL,
# redis://:password@hostname:port/db_number
broker=f"redis://:{REDIS_PASS}@{REDIS_HOST}:{REDIS_PORT}/0",
backend=f"redis://:{REDIS_PASS}@{REDIS_HOST}:{REDIS_PORT}/0",
task_concurrency=4,
worker_prefetch_multiplier=1,
task_serializer="json",