Skip to main content

ExecutionCounters

Struct ExecutionCounters 

Source
pub struct ExecutionCounters { /* private fields */ }
Expand description

Tracks execution progress for concurrent operations.

This struct uses atomic counters to safely track the number of successful, failed, and completed tasks across concurrent executions.

§Examples

use durable_execution_sdk::concurrency::ExecutionCounters;

let counters = ExecutionCounters::new(5);
assert_eq!(counters.total_tasks(), 5);
assert_eq!(counters.success_count(), 0);
assert_eq!(counters.failure_count(), 0);

// Record some completions
counters.complete_task();
counters.complete_task();
counters.fail_task();

assert_eq!(counters.success_count(), 2);
assert_eq!(counters.failure_count(), 1);
assert_eq!(counters.completed_count(), 3);
assert_eq!(counters.pending_count(), 2);

§Memory Ordering

The counters use Ordering::Relaxed for increments (only need atomicity) and Ordering::Acquire for loads (need to see latest writes from other threads). Note that reading multiple counters is not atomic - there may be slight inconsistencies between reads, which is acceptable for progress tracking.

Implementations§

Source§

impl ExecutionCounters

Source

pub fn new(total_tasks: usize) -> Self

Creates a new ExecutionCounters with the given total task count.

Source

pub fn complete_task(&self) -> usize

Records a successful task completion.

Returns the new success count.

§Memory Ordering

Uses Ordering::Relaxed for increments - we only need atomicity, not synchronization with other data. The counters are independent values.

Requirements: 4.1, 4.6

Source

pub fn fail_task(&self) -> usize

Records a failed task.

Returns the new failure count.

§Memory Ordering

Uses Ordering::Relaxed for increments - we only need atomicity.

Requirements: 4.1, 4.6

Source

pub fn suspend_task(&self) -> usize

Records a suspended task.

Returns the new suspended count.

§Memory Ordering

Uses Ordering::Relaxed for increments - we only need atomicity.

Requirements: 4.1, 4.6

Source

pub fn total_tasks(&self) -> usize

Returns the total number of tasks.

§Memory Ordering

Uses Ordering::Acquire to ensure we see the latest value written by other threads. This is important for making completion decisions.

Requirements: 4.3, 4.6

Source

pub fn success_count(&self) -> usize

Returns the current success count.

§Memory Ordering

Uses Ordering::Acquire to ensure we see the latest value.

Requirements: 4.3, 4.6

Source

pub fn failure_count(&self) -> usize

Returns the current failure count.

§Memory Ordering

Uses Ordering::Acquire to ensure we see the latest value.

Requirements: 4.3, 4.6

Source

pub fn completed_count(&self) -> usize

Returns the current completed count (success + failure).

§Memory Ordering

Uses Ordering::Acquire to ensure we see the latest value.

Requirements: 4.3, 4.6

Source

pub fn suspended_count(&self) -> usize

Returns the current suspended count.

§Memory Ordering

Uses Ordering::Acquire to ensure we see the latest value.

Requirements: 4.3, 4.6

Source

pub fn pending_count(&self) -> usize

Returns the number of pending tasks (not yet completed or suspended).

Source

pub fn is_min_successful_reached(&self, min_successful: usize) -> bool

Checks if the minimum successful count has been reached.

§Arguments
  • min_successful - The minimum number of successful tasks required
Source

pub fn is_failure_tolerance_exceeded(&self, config: &CompletionConfig) -> bool

Checks if the failure tolerance has been exceeded.

§Arguments
  • config - The completion configuration with tolerance settings
Source

pub fn should_complete( &self, config: &CompletionConfig, ) -> Option<CompletionReason>

Determines if the operation should complete based on the completion config.

Returns Some(CompletionReason) if the operation should complete, or None if it should continue.

§Arguments
  • config - The completion configuration
Source

pub fn all_completed(&self) -> bool

Checks if all tasks have completed (success or failure, not suspended).

Source

pub fn has_pending(&self) -> bool

Checks if any tasks are still pending.

Trait Implementations§

Source§

impl Debug for ExecutionCounters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExecutionCounters

Source§

fn default() -> Self

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more