dm_database_sqllog2db/tui/
progress.rs1use std::sync::Arc;
4use std::sync::atomic::{AtomicU64, Ordering};
5
6#[derive(Debug, Clone)]
8pub enum ProgressEvent {
9 Started {
11 total_files: usize,
12 exporter_name: String,
13 },
14 FileStarted {
16 file_index: usize,
17 file_name: String,
18 },
19 BatchExported {
21 file_index: usize,
22 records: usize,
23 errors: usize,
24 },
25 FileCompleted { file_index: usize },
27 Completed {
29 total_records: usize,
30 total_errors: usize,
31 elapsed_secs: f64,
32 },
33 Error { message: String },
35}
36
37#[derive(Debug, Clone)]
40pub struct ProgressTracker {
41 current_file_index: Arc<AtomicU64>,
42 total_records: Arc<AtomicU64>,
43 total_errors: Arc<AtomicU64>,
44}
45
46impl ProgressTracker {
47 #[must_use]
48 pub fn new() -> Self {
49 Self {
50 current_file_index: Arc::new(AtomicU64::new(0)),
51 total_records: Arc::new(AtomicU64::new(0)),
52 total_errors: Arc::new(AtomicU64::new(0)),
53 }
54 }
55
56 pub fn set_file_index(&self, index: u64) {
57 self.current_file_index.store(index, Ordering::Relaxed);
58 }
59
60 pub fn add_records(&self, count: u64) {
61 self.total_records.fetch_add(count, Ordering::Relaxed);
62 }
63
64 pub fn add_errors(&self, count: u64) {
65 self.total_errors.fetch_add(count, Ordering::Relaxed);
66 }
67
68 #[must_use]
69 pub fn get_file_index(&self) -> u64 {
70 self.current_file_index.load(Ordering::Relaxed)
71 }
72
73 #[must_use]
74 pub fn get_total_records(&self) -> u64 {
75 self.total_records.load(Ordering::Relaxed)
76 }
77
78 #[must_use]
79 pub fn get_total_errors(&self) -> u64 {
80 self.total_errors.load(Ordering::Relaxed)
81 }
82}
83
84impl Default for ProgressTracker {
85 fn default() -> Self {
86 Self::new()
87 }
88}