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
impl BatchOperationTracker
Sourcepub fn new(
operation_name: impl Into<String>,
total_batches: u64,
total_rows: u64,
) -> Self
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 operationtotal_batches: Total number of batches to processtotal_rows: Total number of rows expected across all batches
Sourcepub fn error_threshold(self, threshold: u64) -> Self
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.
Sourcepub fn smoothing_window(self, size: usize) -> Self
pub fn smoothing_window(self, size: usize) -> Self
Set the smoothing window size for rate calculation.
Sourcepub fn complete_batch(&mut self, rows_in_batch: u64)
pub fn complete_batch(&mut self, rows_in_batch: u64)
Sourcepub fn record_error(&mut self)
pub fn record_error(&mut self)
Record an error.
Sourcepub fn record_errors(&mut self, count: u64)
pub fn record_errors(&mut self, count: u64)
Record multiple errors.
Sourcepub fn operation_name(&self) -> &str
pub fn operation_name(&self) -> &str
Get the operation name.
Sourcepub fn completed_batches(&self) -> u64
pub fn completed_batches(&self) -> u64
Get the number of completed batches.
Sourcepub fn total_batches(&self) -> u64
pub fn total_batches(&self) -> u64
Get the total number of batches.
Sourcepub fn processed_rows(&self) -> u64
pub fn processed_rows(&self) -> u64
Get the number of processed rows.
Sourcepub fn total_rows(&self) -> u64
pub fn total_rows(&self) -> u64
Get the total number of rows.
Sourcepub fn error_count(&self) -> u64
pub fn error_count(&self) -> u64
Get the error count.
Sourcepub fn current_state(&self) -> BatchState
pub fn current_state(&self) -> BatchState
Get the current state.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if the operation is complete.
Sourcepub fn batch_percentage(&self) -> f64
pub fn batch_percentage(&self) -> f64
Calculate the batch completion percentage.
Sourcepub fn row_percentage(&self) -> f64
pub fn row_percentage(&self) -> f64
Calculate the row completion percentage.
Sourcepub fn elapsed_secs(&self) -> f64
pub fn elapsed_secs(&self) -> f64
Calculate the elapsed time in seconds.
Sourcepub fn throughput(&self) -> f64
pub fn throughput(&self) -> f64
Calculate the smoothed throughput (rows per second).
Uses recent batch times for a more stable rate.
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Calculate the success rate percentage.
Sourcepub fn render_plain(&self) -> String
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
Sourcepub fn render_styled(&self) -> String
pub fn render_styled(&self) -> String
Render with ANSI styling.
Two-line display with progress bar, row count, rate, and errors.
Sourcepub fn render_summary(&self) -> String
pub fn render_summary(&self) -> String
Render a completion summary.
Shows total time, rows, average rate, error count, and success rate.
Trait Implementations§
Source§impl Clone for BatchOperationTracker
impl Clone for BatchOperationTracker
Source§fn clone(&self) -> BatchOperationTracker
fn clone(&self) -> BatchOperationTracker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more