retry_policy.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:mWorkerService 作者: smices 项目源码 文件源码
def should_retry(self, error, retries_attempted):
        """Return true if the http client should retry the request.

        :param error: the caught error.
        :type error: Exception
        :param retries_attempted: the number of retries which has been attempted before.
        :type retries_attempted: int
        :return: true if the http client should retry the request.
        :rtype: bool
        """

        # stop retrying when the maximum number of retries is reached
        if retries_attempted >= self.max_error_retry:
            return False

        # always retry on IOError
        if isinstance(error, IOError):
            _logger.debug('Retry for IOError.')
            return True

        # Only retry on a subset of service exceptions
        if isinstance(error, BceServerError):
            if error.status_code == httplib.INTERNAL_SERVER_ERROR:
                _logger.debug('Retry for internal server error.')
                return True
            if error.status_code == httplib.SERVICE_UNAVAILABLE:
                _logger.debug('Retry for service unavailable.')
                return True
            if error.code == BceServerError.REQUEST_EXPIRED:
                _logger.debug('Retry for request expired.')
                return True

        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号