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?
Let's make a simple overview of possible solutions:
Threads are bad solution - because they are live only before your response is not send.
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)
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With