Example #1
0
    def _handle_retry_and_timeout(self, endpoint, request, signer):
        # TODO: replace it with a retry_handler
        # it's a temporary implementation. the long-term plan will be a group a normalized handlers
        # which contains retry_handler and timeout_handler

        # decide whether we should initialize a ClientToken for the request
        retry_policy_context = RetryPolicyContext(request, None, 0, None)
        if self._retry_policy.should_retry(retry_policy_context) & \
                RetryCondition.SHOULD_RETRY_WITH_CLIENT_TOKEN:
            self._add_request_client_token(request)

        request_timeout = self._get_request_timeout(request)

        retryable = RetryCondition.SHOULD_RETRY
        retries = 0

        while True:

            status, headers, body, exception = self._handle_single_request(
                endpoint, request, request_timeout, signer)
            retry_policy_context = RetryPolicyContext(request, exception,
                                                      retries, status)
            retryable = self._retry_policy.should_retry(retry_policy_context)
            if retryable & RetryCondition.NO_RETRY:
                break
            retry_policy_context.retryable = retryable
            time_to_sleep = self._retry_policy.compute_delay_before_next_retry(
                retry_policy_context)
            time.sleep(time_to_sleep / 1000.0)
            retries += 1

        if isinstance(exception, ClientException):
            raise exception

        return status, headers, body, exception
 def _get_retryable(*conditions):
     context = RetryPolicyContext(*conditions)
     return default_retry_policy.should_retry(context)