This is an automated email from the ASF dual-hosted git repository.

klueska pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ad9bcc  Added `retry` argument to `request()` method in Python 
library.
5ad9bcc is described below

commit 5ad9bcc99783eca6c61c7d0851b24a391d417134
Author: Armand Grillet <armand.gril...@outlook.com>
AuthorDate: Mon Oct 15 13:00:54 2018 +0200

    Added `retry` argument to `request()` method in Python library.
    
    This allows us to do HTTP requests without using `tenacity.retry()`. We
    need to be able to disable these retries to stream data for a long
    period of time, such as when using the upcoming `mesos task exec`.
    
    Review: https://reviews.apache.org/r/69023
---
 src/python/lib/mesos/http.py | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/python/lib/mesos/http.py b/src/python/lib/mesos/http.py
index cd15877..5a8016d 100644
--- a/src/python/lib/mesos/http.py
+++ b/src/python/lib/mesos/http.py
@@ -223,6 +223,7 @@ class Resource():
     def request(self,
                 method,
                 additional_headers=None,
+                retry=True,
                 timeout=None,
                 auth=None,
                 use_gzip_encoding=None,
@@ -236,6 +237,8 @@ class Resource():
         :type method: str
         :param additional_headers: additional headers to include in the request
         :type additional_headers: dict[str, str]
+        :param retry: boolean indicating whether to retry if the request fails
+        :type retry: boolean
         :param timeout: timeout in seconds, overrides default_timeout_secs
         :type timeout: float
         :param timeout: timeout in seconds
@@ -254,26 +257,29 @@ class Resource():
         :return: HTTP response
         :rtype: requests.Response
         """
-        if max_attempts is None:
-            max_attempts = self.default_max_attempts
-
-        # We retry only when it makes sense: either due to a network partition
-        # (e.g. connection errors) or if the request failed due to a server
-        # error such as 500s, timeouts, and so on.
-        request_with_retry = tenacity.retry(
-            stop=tenacity.stop_after_attempt(max_attempts),
-            wait=tenacity.wait_exponential(),
-            retry=tenacity.retry_if_exception_type((
-                requests.exceptions.Timeout,
-                requests.exceptions.ConnectionError,
-                MesosServiceUnavailableException,
-                MesosInternalServerErrorException,
-            )),
-            reraise=True,
-        )(self._request)
+        request = self._request
+
+        if retry:
+            if max_attempts is None:
+                max_attempts = self.default_max_attempts
+
+            # We retry only when it makes sense: either due to a network
+            # partition (e.g. connection errors) or if the request failed
+            # due to a server error such as 500s, timeouts, and so on.
+            request = tenacity.retry(
+                stop=tenacity.stop_after_attempt(max_attempts),
+                wait=tenacity.wait_exponential(),
+                retry=tenacity.retry_if_exception_type((
+                    requests.exceptions.Timeout,
+                    requests.exceptions.ConnectionError,
+                    MesosServiceUnavailableException,
+                    MesosInternalServerErrorException,
+                )),
+                reraise=True,
+            )(request)
 
         try:
-            return request_with_retry(
+            return request(
                 method=method,
                 additional_headers=additional_headers,
                 timeout=timeout,

Reply via email to