Skip to main content

BatchOperationTracker

Struct BatchOperationTracker 

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

A tracker for bulk database operations with batch-level progress.

Tracks:

  • Batch-level progress (batch X of Y)
  • Row-level progress (rows processed / total)
  • Error counting with configurable threshold
  • Smoothed rate calculation using recent batch times

§Rendering Modes

  • Rich mode: Two-line display with progress bar, row count, rate, errors
  • Plain mode: Single line for agents
  • JSON mode: Structured data for programmatic consumption

§Example

use sqlmodel_console::renderables::BatchOperationTracker;

let mut tracker = BatchOperationTracker::new("Migrating users", 10, 1000);
tracker.complete_batch(100);
tracker.complete_batch(100);

assert_eq!(tracker.completed_batches(), 2);
assert_eq!(tracker.processed_rows(), 200);

Implementations§

Source§

impl BatchOperationTracker

Source

pub fn new( operation_name: impl Into<String>, total_batches: u64, total_rows: u64, ) -> Self

Create a new batch operation tracker.

§Arguments
  • operation_name: Human-readable name for the operation
  • total_batches: Total number of batches to process
  • total_rows: Total number of rows expected across all batches
Source

pub fn theme(self, theme: Theme) -> Self

Set the theme for styled output.

Source

pub fn error_threshold(self, threshold: u64) -> Self

Set the error threshold for warning state.

When error_count exceeds this threshold, the tracker shows error styling.

Source

pub fn width(self, width: usize) -> Self

Set the rendering width.

Source

pub fn smoothing_window(self, size: usize) -> Self

Set the smoothing window size for rate calculation.

Source

pub fn complete_batch(&mut self, rows_in_batch: u64)

Record completion of a batch.

§Arguments
  • rows_in_batch: Number of rows processed in this batch
Source

pub fn record_error(&mut self)

Record an error.

Source

pub fn record_errors(&mut self, count: u64)

Record multiple errors.

Source

pub fn operation_name(&self) -> &str

Get the operation name.

Source

pub fn completed_batches(&self) -> u64

Get the number of completed batches.

Source

pub fn total_batches(&self) -> u64

Get the total number of batches.

Source

pub fn processed_rows(&self) -> u64

Get the number of processed rows.

Source

pub fn total_rows(&self) -> u64

Get the total number of rows.

Source

pub fn error_count(&self) -> u64

Get the error count.

Source

pub fn current_state(&self) -> BatchState

Get the current state.

Source

pub fn is_complete(&self) -> bool

Check if the operation is complete.

Source

pub fn batch_percentage(&self) -> f64

Calculate the batch completion percentage.

Source

pub fn row_percentage(&self) -> f64

Calculate the row completion percentage.

Source

pub fn elapsed_secs(&self) -> f64

Calculate the elapsed time in seconds.

Source

pub fn throughput(&self) -> f64

Calculate the smoothed throughput (rows per second).

Uses recent batch times for a more stable rate.

Source

pub fn success_rate(&self) -> f64

Calculate the success rate percentage.

Source

pub fn render_plain(&self) -> String

Render as plain text for agents.

Format: Name: 50% (10/20 batches), 5000/10000 rows, 523 rows/s, 0 errors

Source

pub fn render_styled(&self) -> String

Render with ANSI styling.

Two-line display with progress bar, row count, rate, and errors.

Source

pub fn render_summary(&self) -> String

Render a completion summary.

Shows total time, rows, average rate, error count, and success rate.

Source

pub fn to_json(&self) -> String

Render as JSON for structured output.

Trait Implementations§

Source§

impl Clone for BatchOperationTracker

Source§

fn clone(&self) -> BatchOperationTracker

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BatchOperationTracker

Source§

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

Formats the value using the given formatter. 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.