cloacina-python::bindings::value_objects::retry
Rust
Structs
Section titled “Structs”class RetryPolicy
Section titled “class RetryPolicy”Binding
Python API:
cloaca.RetryPolicy
Python wrapper for RetryPolicy
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
inner |
cloacina::retry::RetryPolicy |
Methods
Section titled “Methods”builder
Section titled “builder”fn builder() -> PyRetryPolicyBuilderPython API:
cloaca.RetryPolicy.builder
Create a builder for constructing RetryPolicy
Source
pub fn builder() -> PyRetryPolicyBuilder { PyRetryPolicyBuilder { max_attempts: None, backoff_strategy: None, initial_delay: None, max_delay: None, retry_condition: None, with_jitter: None, } }default
Section titled “default”fn default() -> SelfPython API:
cloaca.RetryPolicy.default
Create a default RetryPolicy
Source
pub fn default() -> Self { Self { inner: cloacina::retry::RetryPolicy::default(), } }should_retry
Section titled “should_retry”fn should_retry(&self, attempt: i32, _error_type: &str) -> boolPython API:
cloaca.RetryPolicy.should_retry
Check if a retry should be attempted
Source
pub fn should_retry(&self, attempt: i32, _error_type: &str) -> bool { // For now, use a simple retry condition check // In the future, this could be enhanced to parse error_type attempt < self.inner.max_attempts }calculate_delay
Section titled “calculate_delay”fn calculate_delay(&self, attempt: i32) -> f64Python API:
cloaca.RetryPolicy.calculate_delay
Calculate delay for a given attempt
Source
pub fn calculate_delay(&self, attempt: i32) -> f64 { let duration = self.inner.calculate_delay(attempt); duration.as_secs_f64() }max_attempts
Section titled “max_attempts”fn max_attempts(&self) -> i32Python API:
cloaca.RetryPolicy.max_attempts
Get maximum number of attempts
Source
pub fn max_attempts(&self) -> i32 { self.inner.max_attempts }initial_delay
Section titled “initial_delay”fn initial_delay(&self) -> f64Python API:
cloaca.RetryPolicy.initial_delay
Get initial delay in seconds
Source
pub fn initial_delay(&self) -> f64 { self.inner.initial_delay.as_secs_f64() }max_delay
Section titled “max_delay”fn max_delay(&self) -> f64Python API:
cloaca.RetryPolicy.max_delay
Get maximum delay in seconds
Source
pub fn max_delay(&self) -> f64 { self.inner.max_delay.as_secs_f64() }with_jitter
Section titled “with_jitter”fn with_jitter(&self) -> boolPython API:
cloaca.RetryPolicy.with_jitter
Check if jitter is enabled
Source
pub fn with_jitter(&self) -> bool { self.inner.jitter }__repr__
Section titled “__repr__”fn __repr__(&self) -> StringPython API:
cloaca.RetryPolicy.__repr__
String representation
Source
pub fn __repr__(&self) -> String { format!( "RetryPolicy(max_attempts={}, initial_delay={}s, max_delay={}s, jitter={})", self.max_attempts(), self.initial_delay(), self.max_delay(), self.with_jitter() ) }from_rust
Section titled “from_rust”pub
fn from_rust(policy: cloacina::retry::RetryPolicy) -> SelfConvert from Rust RetryPolicy (for internal use)
Source
pub fn from_rust(policy: cloacina::retry::RetryPolicy) -> Self { Self { inner: policy } }to_rust
Section titled “to_rust”pub
fn to_rust(&self) -> cloacina::retry::RetryPolicyConvert to Rust RetryPolicy (for internal use)
Source
pub fn to_rust(&self) -> cloacina::retry::RetryPolicy { self.inner.clone() }class BackoffStrategy
Section titled “class BackoffStrategy”Binding
Python API:
cloaca.BackoffStrategy
Python wrapper for BackoffStrategy
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
inner |
cloacina::retry::BackoffStrategy |
Methods
Section titled “Methods”fn fixed() -> SelfPython API:
cloaca.BackoffStrategy.fixed
Fixed delay strategy
Source
pub fn fixed() -> Self { Self { inner: cloacina::retry::BackoffStrategy::Fixed, } }linear
Section titled “linear”fn linear(multiplier: f64) -> SelfPython API:
cloaca.BackoffStrategy.linear
Linear backoff strategy
Source
pub fn linear(multiplier: f64) -> Self { Self { inner: cloacina::retry::BackoffStrategy::Linear { multiplier }, } }exponential
Section titled “exponential”fn exponential(base: f64, multiplier: Option<f64>) -> SelfPython API:
cloaca.BackoffStrategy.exponential
Exponential backoff strategy
CLOACI-T-0882: multiplier is Option and defaults to 1.0 via
unwrap_or below, but pyo3 does NOT infer optionality from Option<T>
— without an explicit signature, the argument stayed REQUIRED and
BackoffStrategy.exponential(2.0) raised
TypeError: missing 1 required positional argument: 'multiplier'.
Nothing had ever constructed one of these from Python, so the gap
between the declared default and the callable signature went unseen.
Source
pub fn exponential(base: f64, multiplier: Option<f64>) -> Self { Self { inner: cloacina::retry::BackoffStrategy::Exponential { base, multiplier: multiplier.unwrap_or(1.0), }, } }__repr__
Section titled “__repr__”fn __repr__(&self) -> StringPython API:
cloaca.BackoffStrategy.__repr__
String representation
Source
pub fn __repr__(&self) -> String { match &self.inner { cloacina::retry::BackoffStrategy::Fixed => "BackoffStrategy.Fixed".to_string(), cloacina::retry::BackoffStrategy::Linear { multiplier } => { format!("BackoffStrategy.Linear(multiplier={})", multiplier) } cloacina::retry::BackoffStrategy::Exponential { base, multiplier } => { format!( "BackoffStrategy.Exponential(base={}, multiplier={})", base, multiplier ) } cloacina::retry::BackoffStrategy::Custom { function_name } => { format!("BackoffStrategy.Custom(function_name='{}')", function_name) } } }class RetryCondition
Section titled “class RetryCondition”Binding
Python API:
cloaca.RetryCondition
Python wrapper for RetryCondition
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
inner |
cloacina::retry::RetryCondition |
Methods
Section titled “Methods”fn never() -> SelfPython API:
cloaca.RetryCondition.never
Never retry
Source
pub fn never() -> Self { Self { inner: cloacina::retry::RetryCondition::Never, } }transient_only
Section titled “transient_only”fn transient_only() -> SelfPython API:
cloaca.RetryCondition.transient_only
Retry only on transient errors
Source
pub fn transient_only() -> Self { Self { inner: cloacina::retry::RetryCondition::TransientOnly, } }all_errors
Section titled “all_errors”fn all_errors() -> SelfPython API:
cloaca.RetryCondition.all_errors
Retry on all errors
Source
pub fn all_errors() -> Self { Self { inner: cloacina::retry::RetryCondition::AllErrors, } }error_pattern
Section titled “error_pattern”fn error_pattern(patterns: Vec<String>) -> SelfPython API:
cloaca.RetryCondition.error_pattern
Retry on specific error patterns
Source
pub fn error_pattern(patterns: Vec<String>) -> Self { Self { inner: cloacina::retry::RetryCondition::ErrorPattern { patterns }, } }__repr__
Section titled “__repr__”fn __repr__(&self) -> StringPython API:
cloaca.RetryCondition.__repr__
String representation
Source
pub fn __repr__(&self) -> String { match &self.inner { cloacina::retry::RetryCondition::Never => "RetryCondition.Never".to_string(), cloacina::retry::RetryCondition::TransientOnly => { "RetryCondition.TransientOnly".to_string() } cloacina::retry::RetryCondition::AllErrors => "RetryCondition.AllErrors".to_string(), cloacina::retry::RetryCondition::ErrorPattern { patterns } => { format!("RetryCondition.ErrorPattern(patterns={:?})", patterns) } } }class RetryPolicyBuilder
Section titled “class RetryPolicyBuilder”Binding
Python API:
cloaca.RetryPolicyBuilder
Python wrapper for RetryPolicy::Builder
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
max_attempts |
Option<i32> |
|
backoff_strategy |
Option<cloacina::retry::BackoffStrategy> |
|
initial_delay |
Option<Duration> |
|
max_delay |
Option<Duration> |
|
retry_condition |
Option<cloacina::retry::RetryCondition> |
|
with_jitter |
Option<bool> |
Methods
Section titled “Methods”max_attempts
Section titled “max_attempts”fn max_attempts(&self, attempts: i32) -> SelfPython API:
cloaca.RetryPolicyBuilder.max_attempts
Set maximum number of retry attempts
Source
pub fn max_attempts(&self, attempts: i32) -> Self { let mut new_builder = self.clone(); new_builder.max_attempts = Some(attempts); new_builder }initial_delay
Section titled “initial_delay”fn initial_delay(&self, delay_seconds: f64) -> SelfPython API:
cloaca.RetryPolicyBuilder.initial_delay
Set initial delay
Source
pub fn initial_delay(&self, delay_seconds: f64) -> Self { let mut new_builder = self.clone(); new_builder.initial_delay = Some(Duration::from_secs_f64(delay_seconds)); new_builder }max_delay
Section titled “max_delay”fn max_delay(&self, delay_seconds: f64) -> SelfPython API:
cloaca.RetryPolicyBuilder.max_delay
Set maximum delay
Source
pub fn max_delay(&self, delay_seconds: f64) -> Self { let mut new_builder = self.clone(); new_builder.max_delay = Some(Duration::from_secs_f64(delay_seconds)); new_builder }backoff_strategy
Section titled “backoff_strategy”fn backoff_strategy(&self, strategy: PyBackoffStrategy) -> SelfPython API:
cloaca.RetryPolicyBuilder.backoff_strategy
Set backoff strategy
Source
pub fn backoff_strategy(&self, strategy: PyBackoffStrategy) -> Self { let mut new_builder = self.clone(); new_builder.backoff_strategy = Some(strategy.inner); new_builder }retry_condition
Section titled “retry_condition”fn retry_condition(&self, condition: PyRetryCondition) -> SelfPython API:
cloaca.RetryPolicyBuilder.retry_condition
Set retry condition
Source
pub fn retry_condition(&self, condition: PyRetryCondition) -> Self { let mut new_builder = self.clone(); new_builder.retry_condition = Some(condition.inner); new_builder }with_jitter
Section titled “with_jitter”fn with_jitter(&self, jitter: bool) -> SelfPython API:
cloaca.RetryPolicyBuilder.with_jitter
Enable/disable jitter
Source
pub fn with_jitter(&self, jitter: bool) -> Self { let mut new_builder = self.clone(); new_builder.with_jitter = Some(jitter); new_builder }fn build(&self) -> PyRetryPolicyPython API:
cloaca.RetryPolicyBuilder.build
Build the RetryPolicy
Source
pub fn build(&self) -> PyRetryPolicy { let mut builder = cloacina::retry::RetryPolicy::builder();
if let Some(attempts) = self.max_attempts { builder = builder.max_attempts(attempts); } if let Some(strategy) = &self.backoff_strategy { builder = builder.backoff_strategy(strategy.clone()); } if let Some(delay) = self.initial_delay { builder = builder.initial_delay(delay); } if let Some(delay) = self.max_delay { builder = builder.max_delay(delay); } if let Some(condition) = &self.retry_condition { builder = builder.retry_condition(condition.clone()); } if let Some(jitter) = self.with_jitter { builder = builder.with_jitter(jitter); }
PyRetryPolicy { inner: builder.build(), } }