0

I'm trying to set up Django-celery-beat in order to create periodic tasks. My configuration is as follows:

from celery import Celery
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')
celery = Celery(broker="django-db")
celery.autodiscover_tasks()

CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
CELERY_ENABLE_UTC = True
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler'

I'm trying to use Django as database and run both the beat service and the workers.

When I launch the workers like this:

celery -A monitoring worker --loglevel=DEBUG --app=config.settings.local

... I get:

ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@django-db:5672//: [Errno 8] nodename nor servname provided, or not known.

And when I try it when beat:

celery -A monitoring beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler --app=config.settings.local

I get this error:

ERROR/MainProcess] beat: Connection error: [Errno 8] nodename nor servname provided, or not known. Trying again in 4.0 seconds...

I'd like to be able to create periodic tasks through the Django admin but I'm stuck at this point so any help is welcome.

loar
  • 1,505
  • 1
  • 15
  • 34

2 Answers2

0

I think you also have to add settings for CELERY_RESULT_BACKEND. Set it to 'django-db' like you did with the broker. If that is not enough try setting the broker in the settings with CELERY_BROKER_URL instead of as a parameter.

Leon
  • 51
  • 5
0

You are using django-db as broker, where celery thinks it is a host address. You should use a real broker address (for e.g. amqp://ip-or-host-here for rabbitmq) instead. Try setting broker_url and remove the broker argument in Celery() to point it to the right direction.

hurturk
  • 5,214
  • 24
  • 41
  • Hi @hurturk, given that I'm using django-celery-beat what's the point of using rabbitmq when I want to use Django as backend? – loar Feb 20 '18 at 08:14
  • Afaik, `django-db` is not a broker but configured for result backend purposes. You still need a broker. – hurturk Feb 20 '18 at 08:59