Merge pull request #4861 from foarsitter/remove_celery_broker_url

Remove CELERY_BROKER_URL in favor of REDIS_URL
This commit is contained in:
Jelmer 2024-10-21 22:21:25 +02:00 committed by GitHub
commit 9806ba7a36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 12 additions and 27 deletions

View File

@ -92,7 +92,7 @@ jobs:
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
env: env:
CELERY_BROKER_URL: "redis://localhost:6379/0" REDIS_URL: "redis://localhost:6379/0"
# postgres://user:password@host:port/database # postgres://user:password@host:port/database
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres" DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"

View File

@ -39,7 +39,6 @@ The following table lists settings and their defaults for third-party applicatio
======================================= =========================== ============================================== ====================================================================== ======================================= =========================== ============================================== ======================================================================
Environment Variable Django Setting Development Default Production Default Environment Variable Django Setting Development Default Production Default
======================================= =========================== ============================================== ====================================================================== ======================================= =========================== ============================================== ======================================================================
CELERY_BROKER_URL CELERY_BROKER_URL auto w/ Docker; raises error w/o raises error
DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error
DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error
DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error

View File

@ -55,8 +55,6 @@ First things first.
#. Set the environment variables for your database(s): :: #. Set the environment variables for your database(s): ::
$ export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/<DB name given to createdb> $ export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/<DB name given to createdb>
# Optional: set broker URL if using Celery
$ export CELERY_BROKER_URL=redis://localhost:6379/0
.. note:: .. note::

View File

@ -86,8 +86,6 @@ it's in the ``Procfile``, but is turned off by default:
.. code-block:: bash .. code-block:: bash
# Set the broker URL to Redis
heroku config:set CELERY_BROKER_URL=`heroku config:get REDIS_URL`
# Scale dyno to 1 instance # Scale dyno to 1 instance
heroku ps:scale worker=1 heroku ps:scale worker=1

View File

@ -33,7 +33,6 @@ docker compose -f docker-compose.local.yml run django python manage.py makemessa
docker compose -f docker-compose.local.yml run \ docker compose -f docker-compose.local.yml run \
-e DJANGO_SECRET_KEY="$(openssl rand -base64 64)" \ -e DJANGO_SECRET_KEY="$(openssl rand -base64 64)" \
-e REDIS_URL=redis://redis:6379/0 \ -e REDIS_URL=redis://redis:6379/0 \
-e CELERY_BROKER_URL=redis://redis:6379/0 \
-e DJANGO_AWS_ACCESS_KEY_ID=x \ -e DJANGO_AWS_ACCESS_KEY_ID=x \
-e DJANGO_AWS_SECRET_ACCESS_KEY=x \ -e DJANGO_AWS_SECRET_ACCESS_KEY=x \
-e DJANGO_AWS_STORAGE_BUCKET_NAME=x \ -e DJANGO_AWS_STORAGE_BUCKET_NAME=x \

View File

@ -7,7 +7,7 @@ environment:
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}' POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_HOST_AUTH_METHOD: trust
{%- if cookiecutter.use_celery == 'y' %} {%- if cookiecutter.use_celery == 'y' %}
CELERY_BROKER_URL: 'redis://redis:6379/0' REDIS_URL: 'redis://redis:6379/0'
{%- endif %} {%- endif %}
steps: steps:

View File

@ -57,7 +57,7 @@ jobs:
env: env:
{%- if cookiecutter.use_celery == 'y' %} {%- if cookiecutter.use_celery == 'y' %}
CELERY_BROKER_URL: 'redis://localhost:6379/0' REDIS_URL: 'redis://localhost:6379/0'
{%- endif %} {%- endif %}
# postgres://user:password@host:port/database # postgres://user:password@host:port/database
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/postgres' DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/postgres'

View File

@ -8,7 +8,7 @@ variables:
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}' POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_HOST_AUTH_METHOD: trust
{%- if cookiecutter.use_celery == 'y' %} {%- if cookiecutter.use_celery == 'y' %}
CELERY_BROKER_URL: 'redis://redis:6379/0' REDIS_URL: 'redis://redis:6379/0'
{%- endif %} {%- endif %}
precommit: precommit:

View File

@ -13,4 +13,4 @@ echo 'Starting flower'
exec watchfiles --filter python celery.__main__.main \ exec watchfiles --filter python celery.__main__.main \
--args \ --args \
"-A config.celery_app -b \"${CELERY_BROKER_URL}\" flower --basic_auth=\"${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}\"" "-A config.celery_app -b \"${REDIS_URL}\" flower --basic_auth=\"${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}\""

View File

@ -125,9 +125,6 @@ RUN chown -R django:django ${APP_HOME}
USER django USER django
RUN DATABASE_URL="" \ RUN DATABASE_URL="" \
{%- if cookiecutter.use_celery == "y" %}
CELERY_BROKER_URL="" \
{%- endif %}
DJANGO_SETTINGS_MODULE="config.settings.test" \ DJANGO_SETTINGS_MODULE="config.settings.test" \
python manage.py compilemessages python manage.py compilemessages

View File

@ -14,6 +14,6 @@ echo 'Starting flower'
exec celery \ exec celery \
-A config.celery_app \ -A config.celery_app \
-b "${CELERY_BROKER_URL}" \ -b "${REDIS_URL}" \
flower \ flower \
--basic_auth="${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}" --basic_auth="${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}"

View File

@ -4,12 +4,6 @@ set -o errexit
set -o pipefail set -o pipefail
set -o nounset set -o nounset
{% if cookiecutter.use_celery == 'y' %}
# N.B. If only .env files supported variable expansion...
export CELERY_BROKER_URL="${REDIS_URL}"
{% endif %}
if [ -z "${POSTGRES_USER}" ]; then if [ -z "${POSTGRES_USER}" ]; then
base_postgres_image_default_user='postgres' base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}" export POSTGRES_USER="${base_postgres_image_default_user}"

View File

@ -282,6 +282,8 @@ LOGGING = {
"root": {"level": "INFO", "handlers": ["console"]}, "root": {"level": "INFO", "handlers": ["console"]},
} }
REDIS_URL = env("REDIS_URL", default="redis://{% if cookiecutter.use_docker == 'y' %}redis{%else%}localhost{% endif %}:6379/0")
{% if cookiecutter.use_celery == 'y' -%} {% if cookiecutter.use_celery == 'y' -%}
# Celery # Celery
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -289,9 +291,9 @@ if USE_TZ:
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone
CELERY_TIMEZONE = TIME_ZONE CELERY_TIMEZONE = TIME_ZONE
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url
CELERY_BROKER_URL = env("CELERY_BROKER_URL") CELERY_BROKER_URL = REDIS_URL
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend
CELERY_RESULT_BACKEND = CELERY_BROKER_URL CELERY_RESULT_BACKEND = REDIS_URL
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended # https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended
CELERY_RESULT_EXTENDED = True CELERY_RESULT_EXTENDED = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-always-retry # https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-always-retry

View File

@ -16,6 +16,7 @@ from sentry_sdk.integrations.redis import RedisIntegration
from .base import * # noqa: F403 from .base import * # noqa: F403
from .base import DATABASES from .base import DATABASES
from .base import INSTALLED_APPS from .base import INSTALLED_APPS
from .base import REDIS_URL
{%- if cookiecutter.use_drf == "y" %} {%- if cookiecutter.use_drf == "y" %}
from .base import SPECTACULAR_SETTINGS from .base import SPECTACULAR_SETTINGS
{%- endif %} {%- endif %}
@ -37,7 +38,7 @@ DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60)
CACHES = { CACHES = {
"default": { "default": {
"BACKEND": "django_redis.cache.RedisCache", "BACKEND": "django_redis.cache.RedisCache",
"LOCATION": env("REDIS_URL"), "LOCATION": REDIS_URL,
"OPTIONS": { "OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient", "CLIENT_CLASS": "django_redis.client.DefaultClient",
# Mimicing memcache behavior. # Mimicing memcache behavior.

View File

@ -26,9 +26,6 @@ else:
sys.path.insert(0, os.path.abspath("..")) sys.path.insert(0, os.path.abspath(".."))
{%- endif %} {%- endif %}
os.environ["DATABASE_URL"] = "sqlite:///readthedocs.db" os.environ["DATABASE_URL"] = "sqlite:///readthedocs.db"
{%- if cookiecutter.use_celery == 'y' %}
os.environ["CELERY_BROKER_URL"] = os.getenv("REDIS_URL", "redis://redis:6379")
{%- endif %}
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
django.setup() django.setup()