Django-celery-email task fails

stuck a bit, solving the problem of sending asynchronous email. I would like to use celery and django database as a backend. since now the only thing I would like to use for this queue management tool is email, I also set up django-celery email.

Following the instructions, I made such updates in the settings file:

import djcelery djcelery.setup_loader() INSTALLED_APPS += ('kombu.transport.django', 'djcelery', 'djcelery_email') BROKER_URL = 'django://' EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend' 

I use django SMTP by default with these settings:

 EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'cs*****@gmail.com' EMAIL_HOST_PASSWORD = '*********' EMAIL_PORT = 587 

I djcelery for djcelery and komby . And now, using the standard django send_mail method, the mail address is not sent.

If the EMAIL_BACKEND option EMAIL_BACKEND removed, sending emails works, but is terribly slow. IF not for speed, I would not look in line for this process in the first place.

I use the MySQL database as the database database and the error log file did not show anything when adding the task, so I assume that this part is in order. It seems to me that I missed some basic part of the installation or configuration, which can be easily noticed by an experienced celery or user djcelery , but a novice like me could miss.

UPDATE Bypass django shell:

 >>> from django.core.mail import send_mail >>> from django.conf import settings >>> result = send_mail('test send', 'test_send_body_text', settings.EMAIL_HOST_USER, 'hornswf@gmail.com') >>> result[0].status u'PENDING' >>> result[0].ready() False >>> result[0].failed() False >>> result[0].info >>> result[0].result 

after 5 minutes of waiting (without sending email with celery it usually takes about 10-15 seconds), I still get:

 >>> result[0].status u'PENDING' 

and after 15 minutes generate the last check (20 in total):

 >>> result[0].status u'PENDING' 

So can anyone help me on this? I firmly believe that it is simple.

Sincerely yours, Sergey Aganezov.

+8
python django django-celery
source share
2 answers

try opening the shell, try sending an email with the djcelery backend and checking the result .

This should be the standard AsyncResult celery, which gives you more information about what is happening.

to indicate from documents

results will be a list of celery AsyncResult objects that you may ignore, or use to check the status of the email delivery task, or even wait for it to complete if want. You have to enable a result backend and set ignore_result to False in CELERY_EMAIL_TASK_CONFIG if you want to use these. See the Celery docs for more info.

EDIT

PENDING is typically intended for tasks that are pending or unknown.

Task is waiting for execution or unknown. Any task id that is not known is implied to be in the pending state Task is waiting for execution or unknown. Any task id that is not known is implied to be in the pending state .

double check that you started your workers:

 ./manage.py celeryd -B 

usually, if the celery cannot send the task to the backend, it gives an error, but the task remains on hold until the employee starts it.

+4
source share

I had a similar problem as indicated in my comment on your question. In my case, the task went to a different queue than the worker listened. By default, the worker listens for the celery queue, but can be changed using the -Q option. The default task will also go to the celery , however I set the "queue" option in CELERY_EMAIL_TASK_CONFIG to something else, not realizing that this would break things. You can debug which queue your task is sent by setting the environment variable KOMBU_LOG_DEBUG=1 and trying to send an email from the manage.py shell. I removed the "queue" setting and emails started working. I don’t know if you are facing the same problem, but hopefully this helps in your debugging.

0
source share

All Articles