marcelo.delta
marcelo.delta

Reputation: 3082

I have problem using Celery, Redis and Django

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.

Upvotes: 2

Views: 4065

Answers (1)

DejanLekic
DejanLekic

Reputation: 19787

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://....

Upvotes: 5

Related Questions