Commits

Matthew Schinckel committed b7e01c3

Automatically retry up to 10 times, with 3 sec delay.
This means client code that calls m.send() does not need to handle transactions
on its own.

  • Participants
  • Parent commits ca11be1

Comments (0)

Files changed (1)

 from sms.models import Message, Gateway
 
 class SendMessage(Task):
+    max_retries = 10
+    default_retry_delay = 3
+    
     def run(self, message_id, gateway_id=None, **kwargs):
         logging.debug("About to send a message.")
         
-        message = Message.objects.get(pk=message_id)
+        # Because we don't always have control over transactions
+        # in our calling code, we will retry up to 10 times, every 3
+        # seconds, in order to try to allow for the commit to the database
+        # to finish. That gives the server 30 seconds to write all of
+        # the data to the database, and finish the view.
+        try:
+            message = Message.objects.get(pk=message_id)
+        except Exception as exc:
+            raise SendMessage.retry(exc=exc)
         
         if not gateway_id:
             if hasattr(message.billee, 'sms_gateway'):