2

I have problem using Celery, Redis and Django.

I am trying to use them to create a simple task.

However, an error occurs shortly after the task has been executed.

I will specify below a part of the code to better understand.I thank you for your attention.

CELERY_BROKER_URL = 'redis://:password@REDIS:6379/0'
CELERY_RESULT_BACKEND = 'redis://REDIS:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = 'America/Recife'
CELERY_BEAT_SCHEDULE = {
    'task-send': {
        'task': 'app.tasks.task_send_email',
        'schedule': crontab(hour=5, minute=44)
    }
}

Console Celery

[config]
app:         sistema:0x7fa254a5d6f4
transport:   redis://:**@redis:6379/0
results:     redis://redis:6379/0
concurrency: 1 (prefork)
task events: OFF (enable -E to monitor tasks in this worker)

[queues]
exchange=celery(direct) key=celery

[tasks]
app.tasks.task_send_email

INFO/MainProcess] Connected to redis://:**@redis:6379/0
INFO/MainProcess] mingle: searching for neighbors
INFO/MainProcess] mingle: all alone

After execute the task a error occur

RuntimeWarning: Exception raised outside body: ResponseError('NOAUTH Authentication required.',):

The task is not completed.

1 Answer 1

5

Considering that your result backend URL does not have the authentication token, and you use the same server that obviously expect it, what I believe is happening is the following: You can successfully run the task (because backend URL is correct), but once the task runs, Celery tries to store the result (in the result backend), but since the result backend URL is invalid (redis://redis:6379/0, should be similar to the broker, ie. redis://:**@redis:6379/1 - use different database name) Celery throws an exception because it can't connect to Redis (NOAUTH Authentication required comes from Redis server).

Let's say your Redis server is redis.local, and your Redis authentication token is my53cr3tt0ken. Your Celery configuration should have these two:

broker_url = "redis://:[email protected]:6379/0"
celery_result_backend = "redis://:[email protected]:6379/1"

Notice I use different databases for broker and result backend - I recommend you do the same.

If your Redis encrypts communication, then you should use rediss://....

Sign up to request clarification or add additional context in comments.

3 Comments

I tried it both ways and it didn't work. redis://:**@redis:6379/1 and redis://:**@celerydb:6379/1
Must by CELERY_BROKER_URL = 'redis://:**@REDIS:6379/0' CELERY_RESULT_BACKEND = 'redis://REDIS:6379/1' ?
Celery 4.0 onwards uses lower-case configuration varibales. I have updated the answer to give you more details, have a look...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.