From 90aa929b738b462aa2ebbb6b47da02830b7d58f6 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 7 Jun 2023 21:15:15 +0200 Subject: [PATCH] feat: show backup time in message --- src/server/process.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/server/process.rs b/src/server/process.rs index a9a9f45..233a678 100644 --- a/src/server/process.rs +++ b/src/server/process.rs @@ -84,6 +84,7 @@ impl ServerProcess { // We wait some time to (hopefully) ensure the save-all call has completed std::thread::sleep(std::time::Duration::from_secs(10)); + let start_time = chrono::offset::Local::now(); let res = self.create_backup_archive(); if res.is_ok() { @@ -93,10 +94,20 @@ impl ServerProcess { // The server's save feature needs to be enabled again even if the archive failed to create self.custom("save-on")?; + let duration = chrono::offset::Local::now() - start_time; + let duration_str = format!( + "{}m{}s", + duration.num_seconds() / 60, + duration.num_seconds() % 60 + ); + if res.is_ok() { - self.custom("say server backed up successfully")?; + self.custom(&format!("say server backed up in {}", duration_str))?; } else { - self.custom("an error occured while backing up the server")?; + self.custom(&format!( + "an error occured after {} while backing up the server", + duration_str + ))?; } res