Skip to content

Commit

Permalink
refactor(hydro_deploy): adjust ProgressTracker::println (#1378)
Browse files Browse the repository at this point in the history
A small refactor pulled out of the perf tracing work, barely related to
#1359
  • Loading branch information
MingweiSamuel committed Aug 13, 2024
1 parent eaf497b commit a88a550
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions hydro_deploy/core/src/localhost/launched_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use futures::io::BufReader;
use futures::{AsyncBufReadExt, AsyncWriteExt};
use tokio::sync::{mpsc, oneshot};

use crate::progress::ProgressTracker;
use crate::util::prioritized_broadcast;
use crate::LaunchedBinary;

Expand All @@ -34,7 +35,7 @@ impl Drop for LaunchedLocalhostBinary {
nix::unistd::Pid::from_raw(pid as i32),
nix::sys::signal::SIGTERM,
) {
eprintln!("Failed to SIGTERM process {}: {}", pid, e);
ProgressTracker::println(format!("Failed to SIGTERM process {}: {}", pid, e));
}
}
}
Expand All @@ -56,11 +57,11 @@ impl LaunchedLocalhostBinary {
let id_clone = id.clone();
let (stdout_cli_receivers, stdout_receivers) = prioritized_broadcast(
BufReader::new(child.stdout.take().unwrap()).lines(),
move |s| println!("[{id_clone}] {s}"),
move |s| ProgressTracker::println(format!("[{id_clone}] {s}")),
);
let (_, stderr_receivers) = prioritized_broadcast(
BufReader::new(child.stderr.take().unwrap()).lines(),
move |s| eprintln!("[{id}] {s}"),
move |s| ProgressTracker::println(format!("[{id} stderr] {s}")),
);

Self {
Expand Down
3 changes: 2 additions & 1 deletion hydro_deploy/core/src/localhost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::{
};
use crate::hydroflow_crate::build::BuildOutput;
use crate::hydroflow_crate::perf_options::PerfOptions;
use crate::progress::ProgressTracker;
use crate::HostStrategyGetter;

pub mod launched_binary;
Expand Down Expand Up @@ -153,7 +154,7 @@ impl LaunchedHost for LaunchedLocalhost {
perf: Option<PerfOptions>,
) -> Result<Box<dyn LaunchedBinary>> {
let mut command = if let Some(perf) = perf {
println!("Profiling binary with perf");
ProgressTracker::println(format!("[{id}] Profiling binary with perf"));
let mut tmp = Command::new("perf");
tmp.args([
"record",
Expand Down
6 changes: 3 additions & 3 deletions hydro_deploy/core/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ impl ProgressTracker {
}

impl ProgressTracker {
pub fn println(msg: &str) {
pub fn println(msg: impl AsRef<str>) {
let progress_bar = PROGRESS_TRACKER
.get_or_init(|| Mutex::new(ProgressTracker::new()))
.lock()
.unwrap();

if progress_bar.multi_progress.println(msg).is_err() {
println!("{}", msg);
if progress_bar.multi_progress.println(msg.as_ref()).is_err() {
println!("{}", msg.as_ref());
}
}

Expand Down
6 changes: 3 additions & 3 deletions hydro_deploy/core/src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl LaunchedBinary for LaunchedSshBinary {
async move {
// Log stderr.
while let Some(Ok(s)) = stderr_lines.next().await {
ProgressTracker::println(&format!("[perf stderr] {s}"));
ProgressTracker::println(format!("[perf stderr] {s}"));
}
Result::<_>::Ok(())
},
Expand Down Expand Up @@ -471,11 +471,11 @@ impl<T: LaunchedSshHost> LaunchedHost for T {
let id_clone = id.clone();
let (stdout_cli_receivers, stdout_receivers) =
prioritized_broadcast(FuturesBufReader::new(channel.stream(0)).lines(), move |s| {
ProgressTracker::println(&format!("[{id_clone}] {s}"));
ProgressTracker::println(format!("[{id_clone}] {s}"));
});
let (_, stderr_receivers) =
prioritized_broadcast(FuturesBufReader::new(channel.stderr()).lines(), move |s| {
ProgressTracker::println(&format!("[{id} stderr] {s}"));
ProgressTracker::println(format!("[{id} stderr] {s}"));
});

Ok(Box::new(LaunchedSshBinary {
Expand Down
2 changes: 1 addition & 1 deletion hydro_deploy/core/src/terraform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl TerraformApply {
let stderr_loop = tokio::task::spawn_blocking(move || {
let mut lines = BufReader::new(stderr).lines();
while let Some(Ok(line)) = lines.next() {
ProgressTracker::println(&format!("[terraform] {}", line));
ProgressTracker::println(format!("[terraform] {}", line));
}
});

Expand Down

0 comments on commit a88a550

Please sign in to comment.