Question

In my django application I am using django-notification to send notifications. However I noticed that in some cases (when sending multiple notifications) my web application is giving delayed responses. Although I am sending notifications through Ajax requests, I still think it would be best if I could implement mailtools library which provide threaded emails.

Has anyone implemented such a thing? Is it easy? How can I use ThreadedMailer from mailtools in django-notification?

or, is there another alternative?

Was it helpful?

Solution

Use Celery for this purpose. It's easy to setup with django and you can use the code you're using right now.

The ajax request puts the email into task queue and returns. You could return your task id if you want to check later if the task succeeded.

Update:

Celery only enables you to call your functions in backgound. Say in ajax view you called:

send_email(…)

Now in tasks.py you should define function:

@task
def send_email(…)

And in the view you will call it by:

send_email.delay(…)

And that's it. The email will be sent by background worker deamon using your existing python code.

This doesn't make django-notification obsolete. Celery does completly different thing and can be used with any lib you can imagine.

The only change is task arguments have to be pickable. It means you have to pass db ids, not whole objects, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top