feat(homelab): add old server
This commit is contained in:
@@ -48,7 +48,7 @@ pub async fn backup_world(state: State, world: &str) -> Result<()> {
|
||||
let reporter = Reporter::new();
|
||||
let job_name = format!("minecraft-{}-backup", world);
|
||||
|
||||
reporter.status(format!("Scaling deployment minecraft-{world}"));
|
||||
reporter.log(format!("Scaling deployment minecraft-{world}"));
|
||||
scale_deployment(&state.client, NAMESPACE, &format!("minecraft-{world}"), 0).await?;
|
||||
|
||||
reporter.status("Creating backup job...");
|
||||
@@ -71,7 +71,7 @@ pub async fn backup_world(state: State, world: &str) -> Result<()> {
|
||||
let succeeded = status.and_then(|s| s.succeeded).unwrap_or(0);
|
||||
let failed = status.and_then(|s| s.failed).unwrap_or(0);
|
||||
|
||||
reporter.status(format!("Scaling deployment minecraft-{world}, replicas: 1"));
|
||||
reporter.log(format!("Scaling deployment minecraft-{world}, replicas: 1"));
|
||||
scale_deployment(&state.client, NAMESPACE, &format!("minecraft-{world}"), 1).await?;
|
||||
if succeeded > 0 {
|
||||
reporter.success("Backup complete");
|
||||
@@ -137,7 +137,7 @@ async fn stream_pod_logs(pods: &Api<Pod>, pod_name: &str, reporter: &Reporter) -
|
||||
let mut lines = stream.lines();
|
||||
|
||||
while let Some(line) = lines.try_next().await? {
|
||||
reporter.log(&line);
|
||||
reporter.log_event(&line);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
|
||||
pub struct Reporter {
|
||||
spinner: ProgressBar,
|
||||
}
|
||||
|
||||
pub const TICK_CHARS: &str = "⣷⣯⣟⡿⢿⣻⣽⣾";
|
||||
|
||||
impl Reporter {
|
||||
pub fn new() -> Self {
|
||||
let spinner = ProgressBar::new_spinner();
|
||||
spinner.set_style(
|
||||
ProgressStyle::default_spinner()
|
||||
.template("{spinner:.cyan} {msg}")
|
||||
.unwrap(),
|
||||
ProgressStyle::with_template(
|
||||
"{prefix:.dim}{msg:>8.214/yellow} {spinner} [{elapsed_precise}]",
|
||||
)
|
||||
.unwrap()
|
||||
.tick_chars(TICK_CHARS),
|
||||
);
|
||||
spinner.enable_steady_tick(std::time::Duration::from_millis(100));
|
||||
Self { spinner }
|
||||
@@ -20,12 +26,16 @@ impl Reporter {
|
||||
self.spinner.set_message(msg.into());
|
||||
}
|
||||
|
||||
pub fn log(&self, line: &str) {
|
||||
pub fn log_event(&self, line: &str) {
|
||||
self.spinner.suspend(|| {
|
||||
println!(" │ {}", line);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn log<T: Display>(&self, text: T) {
|
||||
self.spinner.suspend(|| println!("{}", text))
|
||||
}
|
||||
|
||||
pub fn success(&self, msg: &str) {
|
||||
self.spinner.finish_with_message(format!("✓ {}", msg));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user