Skip to content

Commit

Permalink
refactor: enhance final report with interval information and improve …
Browse files Browse the repository at this point in the history
…Ctrl-C handler reporting
  • Loading branch information
Kremilly committed Jan 30, 2025
1 parent 2fd6204 commit 5bb2c4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 19 additions & 6 deletions src/core/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ impl Dump {
}
}

fn final_report(&self) {
let dump_file_path_clone = self.dump_file_path.clone();
let interval = self.interval;

let dump_count = DUMP_COUNT.load(Ordering::SeqCst);

if let Some(last_dump) = DumpHandlers.get_most_recent_sql_file(&dump_file_path_clone) {
ReportAlerts::report(&dump_file_path_clone, dump_count, &last_dump, interval as usize);
}
}

fn exec(&self) -> Result<(), &'static str> {
let dump_file_path = DumpHandlers.generate_dump_file_path(&self.dbname, &self.dump_file_path);
let password = if self.password.is_empty() { "" } else { &self.password };
Expand All @@ -98,19 +109,20 @@ impl Dump {

fn setup_ctrlc_handler(&self, running: Arc<AtomicBool>) {
let dump_file_path_clone = self.dump_file_path.clone();

let interval = self.interval;

ctrlc::set_handler(move || {
running.store(false, Ordering::SeqCst);

let dump_count = DUMP_COUNT.load(Ordering::SeqCst);

if let Some(last_dump) = DumpHandlers.get_most_recent_sql_file(&dump_file_path_clone) {
ReportAlerts::report(&dump_file_path_clone, dump_count, &last_dump);
ReportAlerts::report(&dump_file_path_clone, dump_count, &last_dump, interval as usize);
}

SuccessAlerts::terminate();
process::exit(0);

}).expect("Error setting Ctrl-C handler");
}

Expand All @@ -126,6 +138,7 @@ impl Dump {
}

if num_dump >= max {
self.final_report();
process::exit(0);
}

Expand Down
3 changes: 2 additions & 1 deletion src/ui/report_alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ pub struct ReportAlerts;

impl ReportAlerts {

pub fn report(dump_file_path: &str, dump_count: usize, last_dump: &str) {
pub fn report(dump_file_path: &str, dump_count: usize, last_dump: &str, interval: usize) {
println!("\nFinal Report:\n");

println!("Directory: {}", dump_file_path.bold().blue());
println!("Interval: {} seconds", interval.to_string().bold().blue());
println!("Total number of dumps: {}", dump_count.to_string().bold().blue());
println!("Last dump: {}", last_dump.bold().cyan());
}
Expand Down

0 comments on commit 5bb2c4c

Please sign in to comment.