- for task in asyncio.as_completed(tasks, loop=self.loop):
- try:
- result = await task
- break
- except ConnectionError:
- continue # ignore; try another endpoint
- else:
- raise errors.JujuConnectionError(
- 'Unable to connect to any endpoint: {}'.format(', '.join([
- endpoint for endpoint, cacert in endpoints])))
+ for attempt in range(self._retries + 1):
+ for task in asyncio.as_completed(tasks, loop=self.loop):
+ try:
+ result = await task
+ break
+ except ConnectionError:
+ continue # ignore; try another endpoint
+ else:
+ _endpoints_str = ', '.join([endpoint
+ for endpoint, cacert in endpoints])
+ if attempt < self._retries:
+ log.debug('Retrying connection to endpoints: {}; '
+ 'attempt {} of {}'.format(_endpoints_str,
+ attempt + 1,
+ self._retries + 1))
+ await asyncio.sleep((attempt + 1) * self._retry_backoff)
+ continue
+ else:
+ raise errors.JujuConnectionError(
+ 'Unable to connect to any endpoint: '
+ '{}'.format(_endpoints_str))
+ # only executed if inner loop's else did not continue
+ # (i.e., inner loop did break due to successful connection)
+ break