0

I'm running a django app and when some event occurs I'd like to send email to a list of recipients.

I know that using Celery would be an intelligent choice, but I'd like to know if there's another, most simple way to do it without having to install a broker server, supervisor to handle the daemon process running in the background...

I'd like to find a more simple way to do it and change it to celery when needed. I'm not in charge of the production server and I know the guy who's running it will have big troubles setting all the configuration to work. I was thinking about firing a django command which opens several processes using multiprocessing library or something like that.

Rod0n
  • 1,019
  • 2
  • 14
  • 33

2 Answers2

0

This is generally a good use case for a queue. If you don't want to run a queue server (like Celery) locally, you have a few options.

  1. There's a number of SaaS queue services out there such as Amazon SQS (and any number of others) that you can hook into your app with no need for additional services running on your machine.

  2. You can implement a kind of "poor man's queue" with a database and a cron job. In this scenario, when your event occurs you can jam some information into your database. Then you can have a cron job fire off a management command that scans your "queued messages" table and sends the emails periodically. Note that this really only works so long as your message queue stays relatively small--if you have so many messages to send, you'll start having to think about having multiple processes sending messages, which opens the can of worms that queueing systems are meant to solve in the first place.

Michael C. O'Connor
  • 9,742
  • 3
  • 37
  • 49
0

If you don't want to implement celery (which in my opinion isn't terribly difficult to setup), then your best bet is probably implementing a very simple queue using either your database. It would probably work along the lines of this:

  1. System determines that an email needs to be sent and creates a row in the database with a status of being 'created' or 'queued'
  2. On the other side there will be a process that scans your "queue" periodically. If they find anything to send (in this case any rows that with status "created/queued", they will update the status to 'sending'. The process will then proceed to send the email and finally update the status to sent.

This will take care of both asynchronously sending the objects and keeping track of the statuses of all emails should things go awry.

You could potentially go with a Redis backend for your queue if the additional updates are too taxing onto your database as well.

daklaw
  • 11
  • 1
  • Might not be terribly difficult for you but it doesn't look like a walk in the park http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html – tread Dec 04 '17 at 10:25