feat: show backup time in message

Jef Roosens 2023-06-07 21:15:15 +02:00
parent 69ce8616d5
commit 19d255b98c
3 changed files with 15 additions and 4 deletions

2
Cargo.lock generated
View File

@ -10,7 +10,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "alex"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"chrono",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "alex"
version = "0.1.0"
version = "0.2.0"
description = "Wrapper around Minecraft server processes, designed to complement Docker image installations."
authors = ["Jef Roosens"]
edition = "2021"

View File

@ -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