Skip to main content

TaskConfig

Struct TaskConfig 

Source
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: RetryMode

Retry 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

Source

pub fn new() -> Self

Create a new TaskConfig with default configuration

Source

pub fn minimal() -> Self

Create a minimal configuration with no retries

Useful for tasks that should fail fast without any retry attempts.

Source

pub fn with_retry(self, retry_mode: RetryMode) -> Self

Set the retry mode for this configuration

Source

pub fn with_fixed_retry(self, retries: usize, delay: Duration) -> Self

Convenience method for fixed retry configuration

Source

pub fn with_exponential_retry(self, max_retries: usize) -> Self

Convenience method for exponential backoff retry configuration

Source

pub fn with_attempt_timeout(self, timeout: Duration) -> Self

Apply a per-attempt timeout. Each retry attempt gets a fresh deadline.

Source

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

Source§

fn clone(&self) -> TaskConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for TaskConfig

Source§

fn default() -> TaskConfig

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.