vintasoftware / django-react-boilerplate

Django 5, React, Bootstrap 5 with Python 3 and Webpack project boilerplate
MIT License
1.94k stars 466 forks source link

Running Locally - Celery/RabbitMQ/Redis #650

Closed txmxthy closed 4 months ago

txmxthy commented 5 months ago

Hi, I am learning all of these tools at once with this project so I don't have a lot of background knowledge on this stuff.

I've followed along through the bootstrap instructions for non-docker setup all the way down to running - I encounter issues around using celery. My env looks like this: I chose sqlite as the db and un-commented it.

DJANGO_SETTINGS_MODULE=tempest.settings.local
CELERY_BROKER_URL=amqp://broker:5672//
REDIS_URL=redis://result:6379
# Please choose postgres or sqlite as your DB:
# DATABASE_URL=postgres://tempest:password@db:5432/tempest
DATABASE_URL=sqlite:///db.sqlite3

Running the worker: poetry run celery --app=tempest worker --loglevel=info image

but we get this response: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [WinError 10061] No connection could be made because the target machine actively refused it. I've been looking through the celery docs and I assume this project uses redis instead of rabbitmq which that CELERY_BROKER_URL port in the env is set up for (5672) and that the celery broker url needs to be changed?

Figured if I am encountering it future people might too and it might be worth an update to the instructions if something does need to be changed? Any help is appreciated!

fjsj commented 5 months ago

I've been looking through the celery docs and I assume this project uses redis instead of rabbitmq which that CELERY_BROKER_URL port in the env is set up for (5672) and that the celery broker url needs to be changed?

Yes, that's right. You need to change CELERY_BROKER_URL to point to redis, as you're not using Docker. Try something like CELERY_BROKER_URL=redis://broker:6379. Let me know if this or something else works for you.

If you can contribute, please open a PR updating the Setup Redis step of README explaining that.

txmxthy commented 5 months ago

I've been looking through the celery docs and I assume this project uses redis instead of rabbitmq which that CELERY_BROKER_URL port in the env is set up for (5672) and that the celery broker url needs to be changed?

Yes, that's right. You need to change CELERY_BROKER_URL to point to redis, as you're not using Docker. Try something like CELERY_BROKER_URL=redis://broker:6379. Let me know if this or something else works for you.

If you can contribute, please open a PR updating the Setup Redis step of README explaining that.

I was able to get it working by adding CELERY_BROKER_URL = config("CELERY_BROKER_URL", default="redis://localhost:6379/0")

into my local_base.py as well as making those changes. I can make a PR but not sure if that is a suitable fix for everyone? It feels out of place there.

fjsj commented 5 months ago

I would say the best PR here is to fix the Setup Redis section of README to explain you need to set CELERY_BROKER_URL in .env to the Redis URL.