Sergey Aganezov jr Sergey Aganezov jr - 1 year ago 168
Python Question

django-celery-email task isn't executed

got a bit stuck solving a problem of asynchronic email sending. I'd like to use celery, and django database as a backend. since for now the only thing I'd like to use this queue managing tool for is email, I've installed django-celery-email as well.

Following the instruction, I've made such updates to my settings file:

import djcelery

INSTALLED_APPS += ('kombu.transport.django',

BROKER_URL = 'django://'
EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'

I'm using default django SMTP with such settings:

EMAIL_HOST_USER = 'cs*****'

I did run migrate for both
apps. And now, using default django
core method, email isn't sent.

If remove
option, email sending works, but horribly slow. IF not for the speed, I wouldn't look for queuing this process in a first place.

I use MySQL database as a database backend, and it's error log file didn't show anything while adding a task, so I assume, that part is fine. It seems to me, I've missed some basic installation or configuration part, that can be easily spot by an experienced celery or
user, but newbie like me could've missed.

django shell work-around:

>>> 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, '')
>>> result[0].status
>>> result[0].ready()
>>> result[0].failed()
>>> result[0].info
>>> result[0].result

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

>>> result[0].status

and after 15 minutes form last check (20 all in all):

>>> result[0].status

So can anyone help me with this issue? I strongly believe it's something simple.

Sincerely yours, Sergey Aganezov.

Answer Source

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

It should be a standard celery AsyncResult that gives you more info on what is happening.

to quote from the docs

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.


usually the PENDING state is for tasks that are waiting the execution or not known.

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

double check you have started your workers:

./ celeryd -B

usually if celery can't send the task to the backend it throws an error, but the task remains pending until a worker acks it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download