Move the original get_draw_order code into the tree_iter module.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Deref;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use tokio::process::Child;
|
||||
use tracing::error;
|
||||
@@ -9,21 +12,22 @@ use crate::nix_util::nix_output_stream::NixAction;
|
||||
use crate::nix_util::output_stream::OutputStream;
|
||||
use crate::nix_util::tree_iter::ForwardTreeIter;
|
||||
|
||||
use super::activity_tree::ActivityId;
|
||||
use super::activity::Activity;
|
||||
use super::activity_tree::ActivityTreeEntry;
|
||||
use super::activity_tree_stream::ActivityTreeStream;
|
||||
use super::nix_output_stream::ActivityResultMessage;
|
||||
use super::nix_output_stream::NixMessage;
|
||||
use super::transparent_iter::TransparentIter;
|
||||
|
||||
pub(crate) struct RunningUpdate {
|
||||
activity_tree: ActivityTreeStream,
|
||||
last_announce: Option<Instant>,
|
||||
}
|
||||
|
||||
impl RunningUpdate {
|
||||
pub(crate) fn new() -> Result<Self> {
|
||||
Ok(RunningUpdate {
|
||||
activity_tree: ActivityTreeStream::new(),
|
||||
last_announce: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -71,11 +75,11 @@ impl RunningUpdate {
|
||||
// }
|
||||
}
|
||||
NixAction::Start(activity_start_message) => {
|
||||
println!("START: {}", serde_json::to_string(&activity_start_message)?);
|
||||
// println!("START: {}", serde_json::to_string(&activity_start_message)?);
|
||||
self.print_current_status();
|
||||
}
|
||||
NixAction::Stop(stop_message) => {
|
||||
println!("STOP: {}", serde_json::to_string(&stop_message)?);
|
||||
// println!("STOP: {}", serde_json::to_string(&stop_message)?);
|
||||
self.print_current_status();
|
||||
}
|
||||
NixAction::Result(activity_result_message) => {
|
||||
@@ -87,19 +91,19 @@ impl RunningUpdate {
|
||||
ActivityResultMessage::SetPhase(_activity_result_set_phase) => {}
|
||||
ActivityResultMessage::Progress(activity_result_progress) => {
|
||||
// if activity_result_progress.expected != 0 {
|
||||
println!(
|
||||
"PROGRESS: {}",
|
||||
serde_json::to_string(&activity_result_progress)?
|
||||
);
|
||||
// println!(
|
||||
// "PROGRESS: {}",
|
||||
// serde_json::to_string(&activity_result_progress)?
|
||||
// );
|
||||
// }
|
||||
self.maybe_print_current_status();
|
||||
}
|
||||
ActivityResultMessage::SetExpected(activity_result_set_expected) => {
|
||||
// if activity_result_set_expected.expected != 0 {
|
||||
println!(
|
||||
"EXPECTED: {}",
|
||||
serde_json::to_string(&activity_result_set_expected)?
|
||||
);
|
||||
// println!(
|
||||
// "EXPECTED: {}",
|
||||
// serde_json::to_string(&activity_result_set_expected)?
|
||||
// );
|
||||
// }
|
||||
self.maybe_print_current_status();
|
||||
}
|
||||
@@ -113,24 +117,81 @@ impl RunningUpdate {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn maybe_print_current_status(&mut self) -> () {}
|
||||
fn maybe_print_current_status(&mut self) -> () {
|
||||
let last_announce = match self.last_announce {
|
||||
Some(instant) => instant,
|
||||
None => {
|
||||
// If we haven't announced before, always announce.
|
||||
return self.print_current_status();
|
||||
}
|
||||
};
|
||||
|
||||
let now = Instant::now();
|
||||
let time_since_last_announce = now.duration_since(last_announce);
|
||||
if time_since_last_announce > Duration::new(5, 0) {
|
||||
return self.print_current_status();
|
||||
}
|
||||
}
|
||||
|
||||
fn print_current_status(&mut self) -> () {
|
||||
let nodes = ForwardTreeIter::new(
|
||||
self.activity_tree.get_tree(),
|
||||
None,
|
||||
|entry| true,
|
||||
|entry| false,
|
||||
|entry| true,
|
||||
is_match_predicate,
|
||||
is_transparent_predicate,
|
||||
is_alive_predicate,
|
||||
);
|
||||
println!("\n\n\nvvvvvv\n\n");
|
||||
for (depth, is_match, is_transparent, node) in nodes {
|
||||
let mut out = Vec::new();
|
||||
for (depth, _is_match, _is_transparent, node) in nodes {
|
||||
let progress_text = node
|
||||
.get_activity()
|
||||
.get_progress_text()
|
||||
.unwrap_or(Cow::Borrowed(""));
|
||||
let name = node
|
||||
.get_activity()
|
||||
.display_name()
|
||||
.unwrap_or(Cow::Borrowed("null"));
|
||||
println!("{depth}\t{is_match}\t{is_transparent}\t{name}");
|
||||
out.push(format!("{depth}\t{progress_text}\t{name}"))
|
||||
}
|
||||
println!("\n\n\n^^^^^^\n\n");
|
||||
|
||||
if out.is_empty() {
|
||||
println!("No active activities.");
|
||||
} else {
|
||||
println!("\n");
|
||||
for l in out {
|
||||
println!("{l}\n");
|
||||
}
|
||||
println!("\n");
|
||||
}
|
||||
self.last_announce = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
|
||||
fn is_match_predicate(entry: &ActivityTreeEntry) -> bool {
|
||||
entry.get_activity().get_progress_text().is_some()
|
||||
}
|
||||
|
||||
pub(crate) fn is_transparent_predicate(entry: &ActivityTreeEntry) -> bool {
|
||||
return false;
|
||||
// match entry.get_activity() {
|
||||
// Activity::Root(_activity_root) => true,
|
||||
// Activity::Unknown(_activity_unknown) => false,
|
||||
// Activity::CopyPath(_activity_copy_path) => false,
|
||||
// Activity::FileTransfer(_activity_file_transfer) => false,
|
||||
// Activity::Realize(_activity_realize) => true,
|
||||
// Activity::CopyPaths(_activity_copy_paths) => true,
|
||||
// Activity::Builds(_activity_builds) => true,
|
||||
// Activity::Build(_activity_build) => false,
|
||||
// Activity::OptimizeStore(_activity_optimize_store) => false,
|
||||
// Activity::VerifyPaths(_activity_verify_paths) => false,
|
||||
// Activity::Substitute(_activity_substitute) => false,
|
||||
// Activity::QueryPathInfo(_activity_query_path_info) => false,
|
||||
// Activity::PostBuildHook(_activity_post_build_hook) => false,
|
||||
// Activity::BuildWaiting(_activity_build_waiting) => true,
|
||||
// Activity::FetchTree(_activity_fetch_tree) => false,
|
||||
// }
|
||||
}
|
||||
|
||||
fn is_alive_predicate(entry: &ActivityTreeEntry) -> bool {
|
||||
entry.get_activity().is_active()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user