Celery: ignoring BROKER_URL in config file

China☆狼群 提交于 2019-12-01 17:03:50

Of course, I realized what I'd done wrong immediately after finishing this question, but I still posted it because someone might find it useful.

My problem is that I copied and pasted code from the tutorial (*facepalm).

I'm overriding the config file when I define the app with a broker arg:

app = Celery('tasks', broker='amqp://guest@localhost//')

Simply remove that:

app = Celery('tasks')

Tada! Everything works fine... and I learned a valuable lesson.

Just for clarification because you are using this:

app.config_from_object('django.conf:settings', namespace='CELERY')

in your celeryconfig.py:

CELERY_BROKER_URL = "amqp://user:password@remote.server.com:5672//vhost"

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ENABLE_UTC = True

Just for anyone else with a similar issue, I ran into a similar problem with a different cause.

I'm using celery with django on heroku, but in my dev environment I am using django-environ to populate environment variables from a file.

I forgot to preface my celery worker command with DJANGO_READ_DOT_ENV_FILE=1

So I went from:

celery -A myapp worker -l info

to

DJANGO_READ_DOT_ENV_FILE=1 celery -A myapp worker -l info

Silly, but a good reminder. Hope it saves someone some time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!