I can not run the celery worker + redis + django. If I run this command to check that celery worker is ready to receive tasks:
celery -A car_rental worker -l info
I got this error:
[2020-02-24 00:14:42,188: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 2.00 seconds...
In my settings.py I have this:
BROKER_URL = 'redis://localhost:6379'
requirements.txt:
amqp==2.5.2, asgiref==3.2.3, billiard==3.6.2.0, celery==4.4.0, redis==3.4.1
celery.py:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'car_rental.settings')
app = Celery('car_rental')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
car_rental/init.py:
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ('celery_app',)
and the structure of my project is like this:
car_rental
/car_rental
__init__.py
celery.py
setting.py
What I didn't understand is that I am using in the broker_url = 'redis://localhost:6379'
but in the error I have: Cannot connect to amqp://guest:**@127.0.0.1:5672//
broker_url
because Celery will look only for parameters that start withCELERY_
and I think that by default Celery try to connect to a rabbitmq server; this is why I get the errorCannot connect to amqp://guest:**@127.0.0.1:5672//
– Bitty