Login

Tag "queue"

Snippet List

Decorator to execute a method only once

Beware if using Amazon Simple Queue Service to execute Celery tasks which send email messages! Sometimes SQS messages are duplicated which results in multiple copies of the messages being sent. This is a simple decorator which uses a cache backend to prevent the task from executing twice in a specified period. For example: @task @execute_once_in(3600*24*7) def cron_first_week_follow_up(): """ Send a follow-up email to new users! """ pass For more info see <http://atodorov.org/blog/2013/12/06/duplicate-amazon-sqs-messages-cause-multiple-emails/> <http://atodorov.org/blog/2013/12/11/idempotent-django-email-sender-with-amazon-sqs-and-memcache/>

  • django
  • email
  • decorator
  • amazon
  • queue
  • celery
Read More

Email queue in DB

This is what I use to send simple status emails from my sites. Instead of a django.core.mail.send_mail call, which can take an irrritatingly, nondeterministically long time to return (regardless of error state), you can stow the emails in the database and rely on a separate interpreter process send them off (using a per-minute cron job or what have you). You then also have a record of everything you've sent via email from your code without having to configure your outbound SMTP server to store them or anything like that. Usage notes are in the docstring; share and enjoy.

  • django
  • python
  • email
  • mail
  • database
  • queue
  • asynchronous
Read More

2 snippets posted so far.