Skip to content

Commit

Permalink
Retries for resolve.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov authored and fkorotkov committed Aug 20, 2015
1 parent 9459369 commit e8c29ed
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def register_options(cls, register):
default=10 * 1024, # 10KB in case jumbo frames are in play.
help='The number of bytes of archive content to buffer in memory before flushing to '
'disk when downloading an archive.')
register('--retries', default=1, advanced=True,
help='How many times to retry to fetch a remote library.')

@memoized_property
def _matchers(self):
Expand Down Expand Up @@ -358,7 +360,12 @@ def _fetch(self, url):
def _download(self, url):
# TODO(jsirois): Wrap with workunits, progress meters, checksums.
self.logger.info('Downloading {}...'.format(url))
with closing(requests.get(url, stream=True)) as res:
session = requests.session()
# Override default http adapters with a retriable one.
retriable_http_adapter = requests.adapters.HTTPAdapter(max_retries=self.get_options().retries)
session.mount("http://", retriable_http_adapter)
session.mount("https://", retriable_http_adapter)
with closing(session.get(url, stream=True)) as res:
if not res.status_code == requests.codes.ok:
raise self.FetchError('Failed to download {} ({} error)'.format(url, res.status_code))
with temporary_file() as archive_fp:
Expand Down

0 comments on commit e8c29ed

Please sign in to comment.