[Updated] [+- ] D9449: phabricator: introduce a `phabricator.retry` option

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sat Nov 28 22:05:28 UTC 2020


marmoute updated this revision to Diff 23791.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9449?vs=23790&id=23791

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D9449/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D9449

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -35,6 +35,20 @@
     # the internal library.
     curlcmd = curl --connect-timeout 2 --retry 3 --silent
 
+    # retry failed command N time (default 0). Useful when using the extension
+    # over flakly connection.
+    #
+    # We wait `retry.interval` between each retry, in seconds.
+    # (default 1 second).
+    retry = 3
+    retry.interval = 10
+
+    # the retry option can combine well with the http.timeout one.
+    #
+    # For example to give up on http request after 20 seconds:
+    [http]
+    timeout=20
+
     [auth]
     example.schemes = https
     example.prefix = phab.example.com
@@ -53,6 +67,7 @@
 import mimetypes
 import operator
 import re
+import time
 
 from mercurial.node import bin, nullid, short
 from mercurial.i18n import _
@@ -136,6 +151,16 @@
 )
 eh.configitem(
     b'phabricator',
+    b'retry',
+    default=0,
+)
+eh.configitem(
+    b'phabricator',
+    b'retry.interval',
+    default=1,
+)
+eh.configitem(
+    b'phabricator',
     b'url',
     default=None,
 )
@@ -400,8 +425,24 @@
     else:
         urlopener = urlmod.opener(ui, authinfo)
         request = util.urlreq.request(pycompat.strurl(url), data=data)
-        with contextlib.closing(urlopener.open(request)) as rsp:
-            body = rsp.read()
+        max_try = ui.configint(b'phabricator', b'retry') + 1
+        error = util.urlerr.urlerror(b"")
+        URLError = error.__class__
+        for try_count in range(max_try):
+            try:
+                with contextlib.closing(urlopener.open(request)) as rsp:
+                    body = rsp.read()
+                break
+            except URLError as err:
+                if try_count == max_try -1:
+                    raise
+                ui.debug(
+                    b'Conduit Request failed (try %d/%d): %r\n'
+                    % (try_count + 1, max_try, err)
+                )
+                # failing request might come from overloaded server
+                retry_interval = ui.configint(b'phabricator', b'retry.interval')
+                time.sleep(retry_interval)
     ui.debug(b'Conduit Response: %s\n' % body)
     parsed = pycompat.rapply(
         lambda x: encoding.unitolocal(x)



To: marmoute, #hg-reviewers
Cc: Kwan, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20201128/f26e2f40/attachment-0002.html>


More information about the Mercurial-patches mailing list