Reviewers: Jakob,

Message:
PTAL

Description:
Add retry feature for push-to-trunk script.

Make url accesses retry. Git retry requires some more analysis of git output
first (follow up CL).

BUG=

Please review this at https://codereview.chromium.org/91733003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+41, -6 lines):
  M tools/push-to-trunk/auto_roll.py
  M tools/push-to-trunk/common_includes.py
  M tools/push-to-trunk/push_to_trunk.py
  M tools/push-to-trunk/test_scripts.py


Index: tools/push-to-trunk/auto_roll.py
diff --git a/tools/push-to-trunk/auto_roll.py b/tools/push-to-trunk/auto_roll.py index cb990cdb173723fb1e660ae327f7a6f57514a05b..ce1a58beca4a94f1cdcbae422265985d17d783c0 100755
--- a/tools/push-to-trunk/auto_roll.py
+++ b/tools/push-to-trunk/auto_roll.py
@@ -62,7 +62,8 @@ class FetchLKGR(Step):

   def RunStep(self):
     lkgr_url = "https://v8-status.appspot.com/lkgr";
-    self.Persist("lkgr", self.ReadURL(lkgr_url))
+    # Retry several times since app engine might have issues.
+    self.Persist("lkgr", self.ReadURL(lkgr_url, wait_plan=[5, 20, 20, 20]))


 class PushToTrunk(Step):
Index: tools/push-to-trunk/common_includes.py
diff --git a/tools/push-to-trunk/common_includes.py b/tools/push-to-trunk/common_includes.py index 4f77c6b4ac728b202db79cad5ff0e06664b07b70..fba82339641d97354319fdf582d6520c5b35625f 100644
--- a/tools/push-to-trunk/common_includes.py
+++ b/tools/push-to-trunk/common_includes.py
@@ -31,6 +31,7 @@ import re
 import subprocess
 import sys
 import textwrap
+import time
 import urllib2

 PERSISTFILE_BASENAME = "PERSISTFILE_BASENAME"
@@ -173,6 +174,7 @@ def MakeChangeLogBugReference(body):
# Some commands don't like the pipe, e.g. calling vi from within the script or
 # from subscripts like git cl upload.
 def Command(cmd, args="", prefix="", pipe=True):
+  # TODO(machenbach): Use timeout.
   cmd_line = "%s %s %s" % (prefix, cmd, args)
   print "Command: %s" % cmd_line
   try:
@@ -200,6 +202,9 @@ class SideEffectHandler(object):
     finally:
       url_fh.close()

+  def Sleep(seconds):
+    time.sleep(seconds)
+
 DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler()


@@ -231,6 +236,27 @@ class Step(object):
   def RunStep(self):
     raise NotImplementedError

+  def Retry(self, cb, retry_on=None, wait_plan=None):
+    retry_on = retry_on or (lambda x: False)
+    wait_plan = list(wait_plan or [])
+    # Sentinel for the first try.
+    wait_plan.append(0)
+    wait_plan.reverse()
+    while wait_plan:
+      got_exception = False
+      try:
+        result = cb()
+      except Exception:
+        got_exception = True
+      if got_exception or retry_on(result):
+        wait_time = wait_plan.pop()
+        print "Waiting for %f seconds." % wait_time
+        self._side_effect_handler.Sleep(wait_time)
+        print "Retrying..."
+      else:
+        return result
+    raise Exception("Retried too often. Giving up.")
+
   def ReadLine(self, default=None):
     # Don't prompt in forced mode.
     if self._options and self._options.f and default is not None:
@@ -239,15 +265,18 @@ class Step(object):
     else:
       return self._side_effect_handler.ReadLine()

-  def Git(self, args="", prefix="", pipe=True):
-    return self._side_effect_handler.Command("git", args, prefix, pipe)
+  def Git(self, args="", prefix="", pipe=True, retry_on=None):
+ cmd = lambda: self._side_effect_handler.Command("git", args, prefix, pipe)
+    return self.Retry(cmd, retry_on, [5, 30])

   def Editor(self, args):
     return self._side_effect_handler.Command(os.environ["EDITOR"], args,
                                              pipe=False)

-  def ReadURL(self, url):
-    return self._side_effect_handler.ReadURL(url)
+  def ReadURL(self, url, retry_on=None, wait_plan=None):
+    wait_plan = wait_plan or [3, 10, 30]
+    cmd = lambda: self._side_effect_handler.ReadURL(url)
+    return self.Retry(cmd, retry_on, wait_plan)

   def Die(self, msg=""):
     if msg != "":
Index: tools/push-to-trunk/push_to_trunk.py
diff --git a/tools/push-to-trunk/push_to_trunk.py b/tools/push-to-trunk/push_to_trunk.py index d78aacbd2b6202170335fb8069fa9ea0858eddd9..cee871fc6e478c403ea6cc78d5ac9f8138e3e515 100755
--- a/tools/push-to-trunk/push_to_trunk.py
+++ b/tools/push-to-trunk/push_to_trunk.py
@@ -102,7 +102,9 @@ class PrepareChangeLog(Step):
     if match:
cl_url = "https://codereview.chromium.org/%s/description"; % match.group(1)
       try:
-        body = self.ReadURL(cl_url)
+ # Fetch from Rietveld but only retry once with one second delay since
+        # there might be many revisions.
+        body = self.ReadURL(cl_url, wait_plan=[1])
       except urllib2.URLError:
         pass
     return body
Index: tools/push-to-trunk/test_scripts.py
diff --git a/tools/push-to-trunk/test_scripts.py b/tools/push-to-trunk/test_scripts.py index f4d0c126ce0fb052221e0618fba4decead97d693..84497be1e4822affe33cfed03e2c665b57131677 100644
--- a/tools/push-to-trunk/test_scripts.py
+++ b/tools/push-to-trunk/test_scripts.py
@@ -269,6 +269,9 @@ class ScriptTest(unittest.TestCase):
   def ReadURL(self, url):
     return self._url_mock.Call(url)

+  def Wait(seconds):
+    pass
+
   def ExpectGit(self, *args):
     """Convenience wrapper."""
     self._git_mock.Expect(*args)


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to