Skip to content

Instantly share code, notes, and snippets.

@mjallday
Created November 22, 2011 08:52
Show Gist options
  • Save mjallday/1385225 to your computer and use it in GitHub Desktop.
Save mjallday/1385225 to your computer and use it in GitHub Desktop.
for transaction in NewsletterTransaction.objects.filter(sent=None):
...
# to
while NewsletterTransaction.objects.filter(sent=None).count():
for transaction in NewletterTransaction.objects.filter(sent=None).limit(10):
...
# taking 10 at a time and then doing a new query. this way you're
# going to know if someone else is updating the db from anther place
# and can use this as a kill switch e.g. run into the db and set
# to some value will stop the process from completing the rest of the
# email send without having to kill the server process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment