[CalendarServer-changes] [3869] CalendarServer/branches/users/wsanchez/deployment/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 16 11:53:46 PDT 2009


Revision: 3869
          http://trac.macosforge.org/projects/calendarserver/changeset/3869
Author:   wsanchez at apple.com
Date:     2009-03-16 11:53:46 -0700 (Mon, 16 Mar 2009)
Log Message:
-----------
Add HTTPRetryAfter option

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py	2009-03-16 18:49:11 UTC (rev 3868)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py	2009-03-16 18:53:46 UTC (rev 3869)
@@ -241,6 +241,9 @@
     # RFC2616 Section 3.5
     "ResponseCompression": True,
 
+    # The retry-after value (in seconds) to return with a 503 error                          
+    "HTTPRetryAfter": 180,
+
     # Set the maximum number of outstanding requests to this server.
     "MaxRequests": 600,
 

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py	2009-03-16 18:49:11 UTC (rev 3868)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py	2009-03-16 18:53:46 UTC (rev 3869)
@@ -14,6 +14,8 @@
 # limitations under the License.
 ##
 
+from random import expovariate
+
 from twisted.internet import protocol
 from twisted.python import log
 from twisted.web2.channel.http import HTTPFactory
@@ -30,13 +32,21 @@
     def connectionMade(self):
         if config.MoreAccessLogData:
             log.msg(overloaded=self)
+
+        retryAfter = int(expovariate(1.0/config.HTTPRetryAfter))
+        if retryAfter > 2 * config.HTTPRetryAfter:
+            retryAfter = config.HTTPRetryAfter
+
         self.transport.write("HTTP/1.0 503 Service Unavailable\r\n"
                              "Content-Type: text/html\r\n"
+                             "Retry-After: %(retryAfter)s\r\n"
                              "Connection: close\r\n\r\n"
                              "<html><head><title>503 Service Unavailable</title></head>"
                              "<body><h1>Service Unavailable</h1>"
                              "The server is currently overloaded, "
-                             "please try again later.</body></html>")
+                             "please try again later.</body></html>"
+                             % { "retryAfter": retryAfter })
+
         self.transport.loseConnection()
 
 class HTTP503LoggingFactory(HTTPFactory):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090316/2a172257/attachment.html>


More information about the calendarserver-changes mailing list