| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 self._grown_factor = grown_factor | 46 self._grown_factor = grown_factor |
| 47 self._timeout_seconds = timeout_seconds | 47 self._timeout_seconds = timeout_seconds |
| 48 self._convert_404_to_None = convert_404_to_None | 48 self._convert_404_to_None = convert_404_to_None |
| 49 | 49 |
| 50 def run(self, request): | 50 def run(self, request): |
| 51 self._total_sleep = 0 | 51 self._total_sleep = 0 |
| 52 self._backoff_seconds = self._initial_backoff_seconds | 52 self._backoff_seconds = self._initial_backoff_seconds |
| 53 while True: | 53 while True: |
| 54 try: | 54 try: |
| 55 return request() | 55 return request() |
| 56 except urllib2.HTTPError, e: | 56 except urllib2.HTTPError as e: |
| 57 if self._convert_404_to_None and e.code == 404: | 57 if self._convert_404_to_None and e.code == 404: |
| 58 return None | 58 return None |
| 59 self._check_for_timeout() | 59 self._check_for_timeout() |
| 60 _log.warn("Received HTTP status %s loading \"%s\". Retrying in
%s seconds..." % | 60 _log.warn("Received HTTP status %s loading \"%s\". Retrying in
%s seconds..." % |
| 61 (e.code, e.filename, self._backoff_seconds)) | 61 (e.code, e.filename, self._backoff_seconds)) |
| 62 self._sleep() | 62 self._sleep() |
| 63 | 63 |
| 64 def _check_for_timeout(self): | 64 def _check_for_timeout(self): |
| 65 if self._total_sleep + self._backoff_seconds > self._timeout_seconds: | 65 if self._total_sleep + self._backoff_seconds > self._timeout_seconds: |
| 66 raise NetworkTimeout() | 66 raise NetworkTimeout() |
| 67 | 67 |
| 68 def _sleep(self): | 68 def _sleep(self): |
| 69 time.sleep(self._backoff_seconds) | 69 time.sleep(self._backoff_seconds) |
| 70 self._total_sleep += self._backoff_seconds | 70 self._total_sleep += self._backoff_seconds |
| 71 self._backoff_seconds *= self._grown_factor | 71 self._backoff_seconds *= self._grown_factor |
| OLD | NEW |