You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by se...@apache.org on 2016/06/13 08:02:44 UTC

yetus git commit: YETUS-419. releasedocmaker should retry when connection fails.

Repository: yetus
Updated Branches:
  refs/heads/master dfd03bdc6 -> b3f28a4d9


YETUS-419. releasedocmaker should retry when connection fails.

Signed-off-by: Kengo Seki <se...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/yetus/repo
Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/b3f28a4d
Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/b3f28a4d
Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/b3f28a4d

Branch: refs/heads/master
Commit: b3f28a4d9911a065aa28f196753ff436c2647a6f
Parents: dfd03bd
Author: Akira Ajisaka <aa...@apache.org>
Authored: Fri Jun 10 16:58:01 2016 +0900
Committer: Kengo Seki <se...@apache.org>
Committed: Mon Jun 13 08:02:01 2016 +0000

----------------------------------------------------------------------
 release-doc-maker/releasedocmaker.py | 39 +++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/yetus/blob/b3f28a4d/release-doc-maker/releasedocmaker.py
----------------------------------------------------------------------
diff --git a/release-doc-maker/releasedocmaker.py b/release-doc-maker/releasedocmaker.py
index 12e4e28..8cffc92 100755
--- a/release-doc-maker/releasedocmaker.py
+++ b/release-doc-maker/releasedocmaker.py
@@ -18,7 +18,7 @@
 
 from glob import glob
 from optparse import OptionParser
-from time import gmtime, strftime
+from time import gmtime, strftime, sleep
 from distutils.version import LooseVersion
 import errno
 import os
@@ -27,6 +27,7 @@ import shutil
 import sys
 import urllib
 import urllib2
+import httplib
 try:
     import json
 except ImportError:
@@ -44,6 +45,7 @@ RELNOTE_PATTERN = re.compile('^\<\!\-\- ([a-z]+) \-\-\>')
 JIRA_BASE_URL = "https://issues.apache.org/jira"
 SORTTYPE = 'resolutiondate'
 SORTORDER = 'older'
+NUM_RETRIES = 5
 CHANGEHDR1 = "| JIRA | Summary | Priority | " + \
              "Component | Reporter | Contributor |\n"
 CHANGEHDR2 = "|:---- |:---- | :--- |:---- |:---- |:---- |\n"
@@ -364,6 +366,11 @@ class JiraIter(object):
         params = urllib.urlencode({'jql': jql,
                                    'startAt': pos,
                                    'maxResults': count})
+        return JiraIter.load_jira(params, 0)
+
+    @staticmethod
+    def load_jira(params, fail_count):
+        """send query to JIRA and collect with retries"""
         try:
             resp = urllib2.urlopen(JIRA_BASE_URL + "/rest/api/2/search?%s" %
                                    params)
@@ -373,10 +380,28 @@ class JiraIter(object):
             if code == 400:
                 print "Please make sure the specified projects are correct."
             sys.exit(1)
-        data = json.loads(resp.read())
+        except httplib.BadStatusLine as err:
+            return JiraIter.retry_load(err, params, fail_count)
+        try:
+            data = json.loads(resp.read())
+        except httplib.IncompleteRead as err:
+            return JiraIter.retry_load(err, params, fail_count)
         return data
 
     @staticmethod
+    def retry_load(err, params, fail_count):
+        """Retry connection up to NUM_RETRIES times."""
+        print(err)
+        fail_count += 1
+        if fail_count <= NUM_RETRIES:
+            print "Connection failed %d times. Retrying." % (fail_count)
+            sleep(1)
+            return JiraIter.load_jira(params, fail_count)
+        else:
+            print "Connection failed %d times. Aborting." % (fail_count)
+            sys.exit(1)
+
+    @staticmethod
     def collect_jiras(ver, projects):
         """send queries to JIRA and collect all issues
         that belongs to given version and projects"""
@@ -694,6 +719,12 @@ def parse_args():
                       action="append",
                       type="string",
                       help="specify base URL of the JIRA instance.")
+    parser.add_option(
+        "--retries",
+        dest="retries",
+        action="append",
+        type="int",
+        help="Specify how many times to retry connection for each URL.")
 
     Linter.add_parser_options(parser)
 
@@ -769,6 +800,10 @@ def main():
     else:
         title = options.title
 
+    if options.retries is not None:
+        global NUM_RETRIES
+        NUM_RETRIES = options.retries[0]
+
     haderrors = False
 
     for version in versions: