Hi Pete,

> I've built a newsletter app that currently cycles through 500+ emails
> and I'd like to have it scale to handle more.

<snip>

> it seems to hang up the browser for quite a while with even just a few
> emails. What is the best way to do this and give the user confirmation
> that the email has been sent to everyone?

Do you have the ability to run a scheduled job (cronjob) on the
server? If so, here's a good way to make this work. It's basically a
batch job rather than an online one.

- Store your recipient email addresses in the database but don't run
your mass mails inside the view.

- Instead, schedule a job to run at a suitable interval as follows.
The job would be a Python/Django standalone script that loops through
"unprocessed" email addresses and sends them the newsletter. See James
Bennett's fantastic write up on standalone scripts here:
http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/

"Unprocessed email addresses": By that I mean something like this,
have a "status" field in your email address table/model. The status
would default to "Not processed". When your script picks up a bunch of
email addresses to mass mail, first mark the status on those addresses
as "Processing", then send your mass mail to those addresses, and
lastly, mark them as "Processed". When your script picks up email
addresses, just make sure it always fetches only the "Not processed"
ones. So, even if a second instance of your script starts a bit before
the first one has finished, the second instance would only pick up
fresh addresses.

Also, maintain a "status_timestamp" field and update it every time the
status is changed. This allows you to run another standalone process
to check if any emails have been stuck in "Processing" status for an
unexpectedly long period of time (most likely indicating that your
mass mailer script failed in the middle.)

> Should I fork off a new process? If so, how can I be sure it finishes
> successfully?

You can make your standalone script log its completion status and
statistics in another table. You can then report to the user how the
job is doing off of data from this table.

You can extend the=is idea by adding a "Job" container that would
manage mass mailing of multiple issues of your newsletter. In that
case, the Job would have its own status field with the same idea (New,
Processing, Processed, Failed)

-Rajesh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to