pub struct TaskConfig {
pub retry_mode: RetryMode,
pub attempt_timeout: Option<Duration>,
pub circuit_breaker: Option<Arc<CircuitBreaker>>,
}Expand description
Task configuration for retry behavior and parameters
This struct provides configuration for task execution behavior, including retry logic and custom parameters.
Fields§
§retry_mode: RetryModeRetry strategy for failed executions
attempt_timeout: Option<Duration>Optional per-attempt timeout. When set, each attempt inside
run_with_retries is wrapped with tokio::time::timeout; an
expired attempt produces a CanoError::Timeout and the retry loop
continues per retry_mode. None (the default) preserves the
previous behavior of letting attempts run unbounded.
circuit_breaker: Option<Arc<CircuitBreaker>>Optional shared CircuitBreaker consulted before each attempt inside
run_with_retries. When the breaker is open the call short-circuits
with CanoError::CircuitOpen without running the task or burning a
retry slot. Share one breaker across multiple tasks to make a trip from
any caller protect every caller.
Implementations§
Source§impl TaskConfig
impl TaskConfig
Sourcepub fn minimal() -> Self
pub fn minimal() -> Self
Create a minimal configuration with no retries
Useful for tasks that should fail fast without any retry attempts.
Sourcepub fn with_retry(self, retry_mode: RetryMode) -> Self
pub fn with_retry(self, retry_mode: RetryMode) -> Self
Set the retry mode for this configuration
Sourcepub fn with_fixed_retry(self, retries: usize, delay: Duration) -> Self
pub fn with_fixed_retry(self, retries: usize, delay: Duration) -> Self
Convenience method for fixed retry configuration
Sourcepub fn with_exponential_retry(self, max_retries: usize) -> Self
pub fn with_exponential_retry(self, max_retries: usize) -> Self
Convenience method for exponential backoff retry configuration
Sourcepub fn with_attempt_timeout(self, timeout: Duration) -> Self
pub fn with_attempt_timeout(self, timeout: Duration) -> Self
Apply a per-attempt timeout. Each retry attempt gets a fresh deadline.
Sourcepub fn with_circuit_breaker(self, breaker: Arc<CircuitBreaker>) -> Self
pub fn with_circuit_breaker(self, breaker: Arc<CircuitBreaker>) -> Self
Attach a shared CircuitBreaker to this configuration.
This is the recommended way to integrate a breaker — the retry loop calls
CircuitBreaker::try_acquire before every attempt and records the
outcome after it returns, so the breaker observes the call’s
success/failure before the workflow propagates it.
Pass the same Arc<CircuitBreaker> to every task that depends on the same
flaky resource so the breaker protects them collectively.
§Short-circuit behavior
An Open breaker short-circuits the call with CanoError::CircuitOpen —
no retries are consumed, the task body is not invoked. A breaker tripped
mid-loop ends the retry loop immediately even when remaining retry
attempts could outlast the breaker’s reset_timeout; recovery requires a
fresh run_with_retries call after the cool-down. This is intentional:
retries against an open breaker would only add load to a dependency the
breaker is already protecting.
Trait Implementations§
Source§impl Clone for TaskConfig
impl Clone for TaskConfig
Source§fn clone(&self) -> TaskConfig
fn clone(&self) -> TaskConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more