Skip to content

Instantly share code, notes, and snippets.

@vkurup
Created July 23, 2014 13:47
Show Gist options
  • Save vkurup/491f95a7c08819009275 to your computer and use it in GitHub Desktop.
Save vkurup/491f95a7c08819009275 to your computer and use it in GitHub Desktop.
Possible race condition
@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