incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [35/50] git commit: [#6531] Added timeout param to urlopen and fixed retries count logging
Date Wed, 28 Aug 2013 14:35:16 GMT
[#6531] Added timeout param to urlopen and fixed retries count logging

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/8c6605d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/8c6605d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/8c6605d3

Branch: refs/heads/tv/6526
Commit: 8c6605d3f32a10b6bd2bd5c19834064c0cdbae34
Parents: 0688afc
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Aug 26 19:09:10 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Aug 26 19:09:10 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8c6605d3/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 8095f79..e545289 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -932,7 +932,7 @@ class exceptionless(object):
         return inner
 
 
-def urlopen(url, retries=3, codes=(408,)):
+def urlopen(url, retries=3, codes=(408,), timeout=None):
     """Open url, optionally retrying if an error is encountered.
 
     Socket timeouts will always be retried if retries > 0.
@@ -942,20 +942,23 @@ def urlopen(url, retries=3, codes=(408,)):
     :param codes: HTTP error codes that should be retried.
 
     """
+    attempts = 0
     while True:
         try:
-            return urllib2.urlopen(url)
+            return urllib2.urlopen(url, timeout=timeout)
         except (urllib2.HTTPError, socket.timeout) as e:
-            if retries and (isinstance(e, socket.timeout) or
+            attempts += 1
+            if attempts < retries and (isinstance(e, socket.timeout) or
                     e.code in codes):
-                retries -= 1
                 continue
             else:
                 try:
                     url_string = url.get_full_url()  # if url is Request obj
                 except Exception:
                     url_string = url
-                log.exception('Failed after %s retries on url: %s: %s', retries, url_string,
e)
+                if timeout is None:
+                    timeout = socket.getdefaulttimeout()
+                log.exception('Failed after %s retries on url with a timeout of %s: %s: %s',
attempts, timeout, url_string, e)
                 raise e
 
 


Mime
View raw message