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
impl ExecutionCounters
Sourcepub fn new(total_tasks: usize) -> Self
pub fn new(total_tasks: usize) -> Self
Creates a new ExecutionCounters with the given total task count.
Sourcepub fn complete_task(&self) -> usize
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
Sourcepub fn fail_task(&self) -> usize
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
Sourcepub fn suspend_task(&self) -> usize
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
Sourcepub fn total_tasks(&self) -> usize
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
Sourcepub fn success_count(&self) -> usize
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
Sourcepub fn failure_count(&self) -> usize
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
Sourcepub fn completed_count(&self) -> usize
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
Sourcepub fn suspended_count(&self) -> usize
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
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of pending tasks (not yet completed or suspended).
Sourcepub fn is_min_successful_reached(&self, min_successful: usize) -> bool
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
Sourcepub fn is_failure_tolerance_exceeded(&self, config: &CompletionConfig) -> bool
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
Sourcepub fn should_complete(
&self,
config: &CompletionConfig,
) -> Option<CompletionReason>
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
Sourcepub fn all_completed(&self) -> bool
pub fn all_completed(&self) -> bool
Checks if all tasks have completed (success or failure, not suspended).
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Checks if any tasks are still pending.
Trait Implementations§
Source§impl Debug for ExecutionCounters
impl Debug for ExecutionCounters
Auto Trait Implementations§
impl !Freeze for ExecutionCounters
impl RefUnwindSafe for ExecutionCounters
impl Send for ExecutionCounters
impl Sync for ExecutionCounters
impl Unpin for ExecutionCounters
impl UnsafeUnpin for ExecutionCounters
impl UnwindSafe for ExecutionCounters
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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