Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Best way to send email in background?

I am sending email from Django (using Webfaction). This is, however, quite slow so I'd like to send the email in the background, returning a response to the user even if the email has not yet been sent.

Any ideas for what is the best way to do this?

I have read about celery, but it seems like a lot of steps to set it up: http://markliu.me/2011/sep/29/django-celery-on-webfaction-using-rabbitmq/ That's Ok, but I'd like to know that this is the way to go before trying it out.

How about threads? http://www.artfulcode.net/articles/threading-django/

Or cron jobs? http://docs.webfaction.com/software/general.html

Others that you have experience with?

like image 926
user984003 Avatar asked Nov 26 '12 14:11

user984003


2 Answers

Let's make a simple overview of possible solutions:

  1. Threads are bad solution - because they are live only before your response is not send.

  2. Celery - is standard way, it's easy to add to django ( just see one of a lot of tutorial about django-celery, for your task using database as broker is enough)

  3. Cron jobs - is not really good programmer's way because your code will store in your repo, and in system crontab. SO everytime you should think about that.

  4. Other way is using something like Eventlet or Gevent. Green threads will live in work in idle, and for your standard task - is very easy to add. Disadvantages: - is you should understand a lot about greenlets, you should be careful for error catching in greenlet.

I recommend to use, Celery because, it's easy to add it now, a lot of tutorial and documentation. Also it's will easy grow up with your application.

like image 166
Rustem Avatar answered Sep 22 '22 05:09

Rustem


I'd probably go with Python RQ. This is a more minimal alternative to Celery and is very easy to set up and to use. You need redis for it though.

like image 43
ptrck Avatar answered Sep 21 '22 05:09

ptrck