Created
July 23, 2014 13:47
-
-
Save vkurup/491f95a7c08819009275 to your computer and use it in GitHub Desktop.
Possible race condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@transaction.atomic | |
def get_pending_messages(): | |
"""Return a list of messages to be sent out and mark them as 'sent' in the db.""" | |
msg_qs = SMSSyncMessage.objects.select_for_update().filter(backend_name=self.name, | |
date_sent=None) | |
messages = [dict(message=m.text, to=m.identity) | |
for m in msg_qs] | |
if msg_qs: | |
msg_qs.update(date_sent=now()) | |
return messages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment