A retry condition determines if a specific error or response warrants a retry attempt.
DefaultRetryCondition
The DefaultRetryCondition triggers a retry if:
- A network error occurs.
- A server-side rate-limiting error occurs.
- The error code is present in the user-defined
retry_error_codes set.
Customizing Retry Conditions
You can implement custom logic by inheriting from RetryCondition or extending DefaultRetryCondition to reuse its existing logic.
Implementing a base RetryCondition:
from volcenginesdkcore.retryer.retry_condition import RetryCondition
class CustomRetryCondition(RetryCondition):
def should_retry(self, response, err):
# type: (RESTResponse, Exception) -> bool
# Access user-defined error codes via self.retry_error_codes
return False
Extending DefaultRetryCondition:
from volcenginesdkcore.retryer.retry_condition import DefaultRetryCondition
class CustomRetryCondition(DefaultRetryCondition):
def should_retry(self, response, err):
# type: (RESTResponse, Exception) -> bool
# Use super() to keep default logic (network/rate-limit/custom codes)
should_retry = super(CustomRetryCondition, self).should_retry(response, err)
# Add additional custom logic here
return should_retry or False
from volcenginesdkcore.retryer.retry_condition import RetryCondition
class CustomRetryCondition(RetryCondition):
def should_retry(
self,
response,
err
):
# type: (RESTResponse, Exception) -> bool
retry_error_codes = self.retry_error_codes # 可以获取到用户自定义的错误码
#................实现自己逻辑
return False