| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import time | 5 import time |
| 6 import urllib | 6 import urllib |
| 7 | 7 |
| 8 | 8 |
| 9 _NO_RETRY_CODE = [200, 302, 401, 403, 404, 501] | 9 _NO_RETRY_CODE = [200, 302, 401, 403, 404, 501] |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 Params: | 59 Params: |
| 60 retry_backoff (float): The base backoff in seconds. | 60 retry_backoff (float): The base backoff in seconds. |
| 61 tries (int): Indicates how many tries have been done. | 61 tries (int): Indicates how many tries have been done. |
| 62 """ | 62 """ |
| 63 if retry_backoff > 1: | 63 if retry_backoff > 1: |
| 64 return retry_backoff * (2 ** (tries - 1)) | 64 return retry_backoff * (2 ** (tries - 1)) |
| 65 else: | 65 else: |
| 66 return retry_backoff | 66 return retry_backoff |
| 67 | 67 |
| 68 def _Retry(self, url, method, data=None, params=None, timeout_seconds=60, | 68 def _Retry(self, url, method, data=None, params=None, timeout_seconds=60, |
| 69 max_retries=5, retry_backoff=1.5, headers=None): | 69 max_retries=5, retry_backoff=1.5, headers=None): |
| 70 if params and method == 'GET': | 70 if params and method == 'GET': |
| 71 url = '%s?%s' % (url, urllib.urlencode(params)) | 71 url = '%s?%s' % (url, urllib.urlencode(params)) |
| 72 | 72 |
| 73 tries = 0 | 73 tries = 0 |
| 74 while tries < max_retries: | 74 while tries < max_retries: |
| 75 tries += 1 | 75 tries += 1 |
| 76 | 76 |
| 77 if method == 'POST': | 77 if method == 'POST': |
| 78 status_code, content = self._Post(url, data, timeout_seconds, headers) | 78 status_code, content = self._Post(url, data, timeout_seconds, headers) |
| 79 elif method == 'PUT': | 79 elif method == 'PUT': |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 returning http status code is not in 200, 302, 401, 403, 404, or 501. | 143 returning http status code is not in 200, 302, 401, 403, 404, or 501. |
| 144 retry_backoff (float): The base backoff in seconds for retry. | 144 retry_backoff (float): The base backoff in seconds for retry. |
| 145 | 145 |
| 146 Returns: | 146 Returns: |
| 147 (status_code, content) | 147 (status_code, content) |
| 148 """ | 148 """ |
| 149 return self._Retry( | 149 return self._Retry( |
| 150 url, method='PUT', data=data, params=None, | 150 url, method='PUT', data=data, params=None, |
| 151 timeout_seconds=timeout_seconds, max_retries=max_retries, | 151 timeout_seconds=timeout_seconds, max_retries=max_retries, |
| 152 retry_backoff=retry_backoff, headers=headers) | 152 retry_backoff=retry_backoff, headers=headers) |
| OLD | NEW |