pub struct BatchStatusWriter { /* private fields */ }Expand description
Accumulates task status changes and flushes them in bulk.
Updates are keyed by (workflow_id, task_id). If a task transitions
multiple times before a flush (e.g., Pending → Running → Completed),
only the most-recent state is retained — this de-duplicates writes for
tasks that complete faster than the flush interval.
Implementations§
Source§impl BatchStatusWriter
impl BatchStatusWriter
Sourcepub fn record(
&mut self,
workflow_id: impl Into<String>,
task_id: impl Into<String>,
state: TaskState,
error: Option<String>,
)
pub fn record( &mut self, workflow_id: impl Into<String>, task_id: impl Into<String>, state: TaskState, error: Option<String>, )
Record a task status change.
If the batch is full after accepting this update, the caller should
call Self::flush before continuing (check Self::needs_flush).
Sourcepub fn needs_flush(&self) -> bool
pub fn needs_flush(&self) -> bool
Return true if the batch should be flushed (batch is full or overflowing).
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Return the number of pending updates.
Sourcepub fn flush<E, F>(&mut self, sink: F) -> Result<FlushResult, E>
pub fn flush<E, F>(&mut self, sink: F) -> Result<FlushResult, E>
Flush all pending updates.
The provided sink callback receives the sorted batch of updates.
After calling sink the internal buffer is cleared regardless of
whether sink succeeds.
§Errors
Returns any error propagated from sink.
Sourcepub fn flush_to_vec(&mut self) -> Vec<StatusUpdate>
pub fn flush_to_vec(&mut self) -> Vec<StatusUpdate>
Flush into a Vec<StatusUpdate> and return it (useful for testing).
Sourcepub fn total_accepted(&self) -> u64
pub fn total_accepted(&self) -> u64
Total number of updates ever accepted.
Sourcepub fn total_flushes(&self) -> u64
pub fn total_flushes(&self) -> u64
Total number of flush operations.
Sourcepub fn set_max_batch_size(&mut self, max: usize)
pub fn set_max_batch_size(&mut self, max: usize)
Change the maximum batch size.
Sourcepub fn max_batch_size(&self) -> usize
pub fn max_batch_size(&self) -> usize
Maximum batch size.