Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Email(models.Model):
- sent = models.BooleanField(default=False)
- subj = models.CharField(max_length=140)
- msg = models.TextField()
- from django.db import connection
- [...]
- class EmailLocks(object):
- def __init__(self):
- self.c = connection.cursor()
- def __enter__(self):
- self.c.execute('''lock tables my_app_email write''')
- def __exit__(self, *err):
- self.c.execute('unlock tables')
- with EmailLocks():
- # read the email table and decide if you need to process it
- for e in Email.objects.filter(sent=False):
- # send the email
- # mark the email as sent
- e.sent = True
- e.save()
- * * * * * /usr/bin/flock -n /tmp/fcj.lockfile /usr/bin/python /home/txuser/dev/Project1/projectnew/manage.py flocktest
Add Comment
Please, Sign In to add comment