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
- decorator
- amazon
- queue
- celery