2026-02-19 18:39:01 -05:00
|
|
|
use std::borrow::Cow;
|
2026-02-17 22:49:42 -05:00
|
|
|
use std::collections::BTreeMap;
|
2026-02-21 21:50:08 -05:00
|
|
|
use std::collections::BTreeSet;
|
2026-02-17 22:49:42 -05:00
|
|
|
|
2026-02-16 20:42:03 -05:00
|
|
|
use sqlx::Row;
|
2026-02-16 20:06:46 -05:00
|
|
|
use tokio::process::Child;
|
2026-02-17 22:49:42 -05:00
|
|
|
use tracing::error;
|
2026-02-21 21:50:08 -05:00
|
|
|
use tracing::warn;
|
2026-02-16 20:06:46 -05:00
|
|
|
|
|
|
|
|
use crate::Result;
|
|
|
|
|
use crate::database::db_handle::DbHandle;
|
2026-02-19 18:39:01 -05:00
|
|
|
use crate::nix_util::nix_output_stream::ActivityStartMessage;
|
2026-02-17 22:49:42 -05:00
|
|
|
use crate::nix_util::nix_output_stream::NixAction;
|
2026-02-16 21:17:25 -05:00
|
|
|
use crate::nix_util::nix_output_stream::NixOutputStream;
|
|
|
|
|
use crate::nix_util::output_stream::OutputStream;
|
|
|
|
|
|
2026-02-19 18:39:01 -05:00
|
|
|
use super::nix_output_stream::ActivityResultMessage;
|
2026-02-16 21:17:25 -05:00
|
|
|
use super::nix_output_stream::NixMessage;
|
2026-02-16 20:06:46 -05:00
|
|
|
|
|
|
|
|
pub(crate) struct RunningBuild<'db> {
|
|
|
|
|
db_handle: &'db DbHandle,
|
2026-02-17 22:49:42 -05:00
|
|
|
activity_tree: BTreeMap<u64, Activity>,
|
2026-02-16 20:06:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'db> RunningBuild<'db> {
|
|
|
|
|
pub(crate) fn new(db_handle: &'db DbHandle) -> Result<Self> {
|
2026-02-17 22:49:42 -05:00
|
|
|
Ok(RunningBuild {
|
|
|
|
|
db_handle,
|
|
|
|
|
activity_tree: BTreeMap::new(),
|
|
|
|
|
})
|
2026-02-16 20:06:46 -05:00
|
|
|
}
|
|
|
|
|
|
2026-02-16 20:42:03 -05:00
|
|
|
pub(crate) async fn run_to_completion<TN>(
|
|
|
|
|
&mut self,
|
|
|
|
|
mut child: Child,
|
|
|
|
|
target_name: TN,
|
|
|
|
|
) -> Result<()>
|
|
|
|
|
where
|
|
|
|
|
TN: AsRef<str>,
|
|
|
|
|
{
|
|
|
|
|
let build_id: i64 = sqlx::query(
|
|
|
|
|
r#"INSERT INTO build (start_time, target) SELECT unixepoch('now'), ? RETURNING id"#,
|
|
|
|
|
)
|
|
|
|
|
.bind(target_name.as_ref())
|
|
|
|
|
.fetch_one(&self.db_handle.conn)
|
|
|
|
|
.await?
|
|
|
|
|
.try_get("id")?;
|
|
|
|
|
|
2026-02-16 21:17:25 -05:00
|
|
|
let output_stream = OutputStream::from_child(&mut child)?;
|
2026-02-17 22:49:42 -05:00
|
|
|
let mut nix_output_stream: NixOutputStream<OutputStream> =
|
|
|
|
|
NixOutputStream::new(output_stream);
|
2026-02-16 20:06:46 -05:00
|
|
|
|
|
|
|
|
let exit_status_handle = tokio::spawn(async move {
|
|
|
|
|
let status = child
|
|
|
|
|
.wait()
|
|
|
|
|
.await
|
|
|
|
|
.expect("nixos-rebuild encountered an error");
|
|
|
|
|
status
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-16 21:17:25 -05:00
|
|
|
while let Some(message) = nix_output_stream.next().await? {
|
|
|
|
|
self.handle_message(message)?;
|
2026-02-16 20:06:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let exit_status = exit_status_handle.await?;
|
2026-02-19 18:39:01 -05:00
|
|
|
println!("nix build status was: {}", exit_status);
|
2026-02-16 20:06:46 -05:00
|
|
|
|
2026-02-16 20:42:03 -05:00
|
|
|
let update: u64 =
|
|
|
|
|
sqlx::query(r#"UPDATE build SET end_time=unixepoch('now'), status=? WHERE id=?"#)
|
|
|
|
|
.bind(
|
|
|
|
|
exit_status
|
|
|
|
|
.code()
|
|
|
|
|
.expect("Process should have an exit code."),
|
|
|
|
|
)
|
|
|
|
|
.bind(build_id)
|
|
|
|
|
.execute(&self.db_handle.conn)
|
|
|
|
|
.await?
|
|
|
|
|
.rows_affected();
|
|
|
|
|
assert!(update == 1);
|
|
|
|
|
|
2026-02-16 20:06:46 -05:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-17 22:49:42 -05:00
|
|
|
pub(crate) fn handle_message(&mut self, message: NixMessage) -> Result<()> {
|
|
|
|
|
let message = match message {
|
|
|
|
|
NixMessage::ParseFailure(line) => {
|
|
|
|
|
error!("FAIL PARSE: {line}");
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
NixMessage::Generic(_value, line) => {
|
|
|
|
|
error!("GENERIC PARSE: {line}");
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
NixMessage::Action(nix_action) => nix_action,
|
|
|
|
|
};
|
2026-02-19 18:39:01 -05:00
|
|
|
match message {
|
|
|
|
|
NixAction::Msg(msg_message) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// For now we can ignore the messages.
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
NixAction::Start(activity_start_message) => {
|
|
|
|
|
let id = activity_start_message.get_id();
|
|
|
|
|
let entry = self.activity_tree.entry(id);
|
2026-02-17 22:49:42 -05:00
|
|
|
let entry = match entry {
|
|
|
|
|
std::collections::btree_map::Entry::Vacant(vacant_entry) => vacant_entry,
|
|
|
|
|
std::collections::btree_map::Entry::Occupied(_occupied_entry) => {
|
|
|
|
|
panic!("Started an already started activity: {id}.")
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-02-19 18:39:01 -05:00
|
|
|
match activity_start_message {
|
|
|
|
|
ActivityStartMessage::Unknown(activity_start_unknown) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::Unknown(ActivityUnknown {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_unknown.id,
|
|
|
|
|
parent: activity_start_unknown.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::CopyPath(activity_start_copy_path) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::CopyPath(ActivityCopyPath {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_copy_path.id,
|
|
|
|
|
parent: activity_start_copy_path.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::FileTransfer(activity_start_file_transfer) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::FileTransfer(ActivityFileTransfer {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_file_transfer.id,
|
|
|
|
|
parent: activity_start_file_transfer.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
2026-02-19 18:39:01 -05:00
|
|
|
url: activity_start_file_transfer.url,
|
2026-02-17 22:49:42 -05:00
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::Realize(activity_start_realize) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::Realize(ActivityRealize {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_realize.id,
|
|
|
|
|
parent: activity_start_realize.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::CopyPaths(activity_start_copy_paths) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::CopyPaths(ActivityCopyPaths {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_copy_paths.id,
|
|
|
|
|
parent: activity_start_copy_paths.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::Builds(activity_start_builds) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::Builds(ActivityBuilds {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_builds.id,
|
|
|
|
|
parent: activity_start_builds.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::Build(activity_start_build) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::Build(ActivityBuild {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_build.id,
|
|
|
|
|
parent: activity_start_build.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
2026-02-19 18:39:01 -05:00
|
|
|
drv_path: activity_start_build.drv_path,
|
2026-02-21 21:50:08 -05:00
|
|
|
machine_name: if activity_start_build.machine_name.len() > 0 {
|
|
|
|
|
Some(activity_start_build.machine_name)
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
},
|
2026-02-17 22:49:42 -05:00
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::OptimizeStore(activity_start_optimize_store) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::OptimizeStore(ActivityOptimizeStore {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_optimize_store.id,
|
|
|
|
|
parent: activity_start_optimize_store.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::VerifyPaths(activity_start_verify_paths) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::VerifyPaths(ActivityVerifyPaths {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_verify_paths.id,
|
|
|
|
|
parent: activity_start_verify_paths.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::Substitute(activity_start_substitute) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::Substitute(ActivitySubstitute {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_substitute.id,
|
|
|
|
|
parent: activity_start_substitute.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::QueryPathInfo(activity_start_query_path_info) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::QueryPathInfo(ActivityQueryPathInfo {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_query_path_info.id,
|
|
|
|
|
parent: activity_start_query_path_info.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::PostBuildHook(activity_start_post_build_hook) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::PostBuildHook(ActivityPostBuildHook {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_post_build_hook.id,
|
|
|
|
|
parent: activity_start_post_build_hook.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::BuildWaiting(activity_start_build_waiting) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::BuildWaiting(ActivityBuildWaiting {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_build_waiting.id,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityStartMessage::FetchTree(activity_start_fetch_tree) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
entry.insert(Activity::FetchTree(ActivityFetchTree {
|
2026-02-19 18:39:01 -05:00
|
|
|
id: activity_start_fetch_tree.id,
|
|
|
|
|
parent: activity_start_fetch_tree.parent,
|
2026-02-17 22:49:42 -05:00
|
|
|
state: ActivityState::default(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
self.print_current_status();
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
NixAction::Stop(stop_message) => {
|
|
|
|
|
let entry = self.activity_tree.entry(stop_message.id);
|
2026-02-17 22:49:42 -05:00
|
|
|
match entry {
|
|
|
|
|
std::collections::btree_map::Entry::Vacant(_vacant_entry) => {
|
2026-02-19 18:39:01 -05:00
|
|
|
panic!(
|
|
|
|
|
"Stopped an activity that is not in the tree: {}",
|
|
|
|
|
stop_message.id
|
|
|
|
|
);
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
|
|
|
|
std::collections::btree_map::Entry::Occupied(mut occupied_entry) => {
|
|
|
|
|
occupied_entry.get_mut().stop();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
self.print_current_status();
|
|
|
|
|
// println!("{}", serde_json::to_string(&message)?);
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
NixAction::Result(activity_result_message) => {
|
|
|
|
|
match activity_result_message {
|
|
|
|
|
ActivityResultMessage::FileLinked(activity_result_file_linked) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// FileLinked
|
|
|
|
|
// TODO: Haven't seen any of these.
|
2026-02-19 18:39:01 -05:00
|
|
|
// warn!("Found FileLinked: {}", serde_json::to_string(&message)?);
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::BuildLogLine(activity_result_build_log_line) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// BuildLogLine
|
|
|
|
|
// The first field is a string containing the log line
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::UntrustedPath(activity_result_untrusted_path) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// UntrustedPath
|
|
|
|
|
// TODO: Haven't seen any of these.
|
2026-02-19 18:39:01 -05:00
|
|
|
// warn!("Found UntrustedPath: {}", serde_json::to_string(&message)?);
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::CorruptedPath(activity_result_corrupted_path) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// CorruptedPath
|
|
|
|
|
// TODO: Haven't seen any of these.
|
2026-02-19 18:39:01 -05:00
|
|
|
// warn!("Found CorruptedPath: {}", serde_json::to_string(&message)?);
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::SetPhase(activity_result_set_phase) => { // SetPhase
|
2026-02-17 22:49:42 -05:00
|
|
|
// The first field is the phase name
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::Progress(activity_result_progress) => { // Progress
|
2026-02-17 22:49:42 -05:00
|
|
|
// Fields numerator, denominator, running?, failed?
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::SetExpected(activity_result_set_expected) => { // SetExpected
|
2026-02-17 22:49:42 -05:00
|
|
|
// Fields activity type?, expected?
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::PostBuildLogLine(
|
|
|
|
|
activity_result_post_build_log_line,
|
|
|
|
|
) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// PostBuildLogLine
|
|
|
|
|
// TODO: Haven't seen any of these.
|
2026-02-19 18:39:01 -05:00
|
|
|
// warn!(
|
|
|
|
|
// "Found PostBuildLogLine: {}",
|
|
|
|
|
// serde_json::to_string(&message)?
|
|
|
|
|
// );
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
ActivityResultMessage::FetchStatus(activity_result_fetch_status) => {
|
2026-02-17 22:49:42 -05:00
|
|
|
// FetchStatus
|
|
|
|
|
// TODO: Haven't seen any of these.
|
2026-02-19 18:39:01 -05:00
|
|
|
// warn!("Found FetchStatus: {}", serde_json::to_string(&message)?);
|
2026-02-17 22:49:42 -05:00
|
|
|
// println!("{}", serde_json::to_string(&message)?);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-02-16 20:06:46 -05:00
|
|
|
Ok(())
|
|
|
|
|
}
|
2026-02-17 22:49:42 -05:00
|
|
|
|
|
|
|
|
fn print_current_status(&self) -> () {
|
2026-02-21 21:50:08 -05:00
|
|
|
let mut tree = String::new();
|
|
|
|
|
let draw_order = self.get_draw_order();
|
|
|
|
|
for dag_entry in draw_order {
|
|
|
|
|
let leading_bars = {
|
|
|
|
|
let mut leading_bars = String::with_capacity(3 * dag_entry.depth.len());
|
|
|
|
|
for leading_bar in dag_entry
|
|
|
|
|
.depth
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|depth| if *depth { " " } else { " " })
|
|
|
|
|
{
|
|
|
|
|
leading_bars.push_str(leading_bar);
|
|
|
|
|
}
|
|
|
|
|
leading_bars
|
|
|
|
|
};
|
|
|
|
|
let branch = if dag_entry.has_later_siblings {
|
|
|
|
|
""
|
|
|
|
|
} else {
|
|
|
|
|
""
|
|
|
|
|
};
|
|
|
|
|
let activity = self
|
|
|
|
|
.activity_tree
|
|
|
|
|
.get(&dag_entry.activity_id)
|
|
|
|
|
.expect("Activity should exist in the tree.");
|
|
|
|
|
let display_name = activity
|
|
|
|
|
.display_name()
|
|
|
|
|
.expect("Currently we always return a display name.");
|
|
|
|
|
let activity_id = activity.get_activity_id();
|
|
|
|
|
let parent_id = activity.get_parent_id();
|
|
|
|
|
tree += &format!("{leading_bars}{branch} {display_name} {parent_id} {activity_id}\n");
|
|
|
|
|
}
|
|
|
|
|
if tree.is_empty() {
|
|
|
|
|
println!("No active activities.");
|
|
|
|
|
} else {
|
|
|
|
|
print!("\n{}\n", tree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_draw_order(&self) -> Vec<DrawDagEntry> {
|
|
|
|
|
let active_activity_ids: BTreeSet<u64> = self
|
2026-02-19 18:39:01 -05:00
|
|
|
.activity_tree
|
|
|
|
|
.iter()
|
2026-02-21 21:50:08 -05:00
|
|
|
.filter(|(activity_id, activity)| activity.is_active())
|
|
|
|
|
.flat_map(|(activity_id, activity)| {
|
|
|
|
|
PathToRootIter::new(&self.activity_tree, *activity_id)
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
let mut draw_order: Vec<DrawDagEntry> = Vec::new();
|
|
|
|
|
let mut stack: Vec<DrawStackEntry> = self
|
|
|
|
|
.get_children_in_order(0)
|
|
|
|
|
.filter_map(|child_id| {
|
|
|
|
|
if active_activity_ids.contains(&child_id) {
|
|
|
|
|
Some(DrawStackEntry::HasNotVisitedChildren(DrawDagEntry {
|
|
|
|
|
activity_id: child_id,
|
|
|
|
|
depth: Vec::new(),
|
|
|
|
|
has_later_siblings: true,
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-02-19 18:39:01 -05:00
|
|
|
.collect();
|
2026-02-21 21:50:08 -05:00
|
|
|
if stack.len() == 0 {
|
|
|
|
|
return draw_order;
|
|
|
|
|
}
|
|
|
|
|
stack
|
|
|
|
|
.last_mut()
|
|
|
|
|
.expect("If-statement ensured this is Some()")
|
|
|
|
|
.set_no_later_siblings();
|
|
|
|
|
|
|
|
|
|
while !stack.is_empty() {
|
|
|
|
|
let current_entry = stack.pop().expect("While-loop ensured this is Some.");
|
|
|
|
|
match current_entry {
|
|
|
|
|
DrawStackEntry::HasNotVisitedChildren(draw_dag_entry) => {
|
|
|
|
|
let current_id = draw_dag_entry.activity_id;
|
|
|
|
|
let mut current_depth = draw_dag_entry.depth.clone();
|
|
|
|
|
current_depth.push(draw_dag_entry.has_later_siblings);
|
|
|
|
|
stack.push(DrawStackEntry::VisitedChildren(draw_dag_entry));
|
|
|
|
|
let children: Vec<u64> = self
|
|
|
|
|
.get_children_in_order(current_id)
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter(|child_id| active_activity_ids.contains(child_id))
|
|
|
|
|
.collect();
|
|
|
|
|
let has_children = !children.is_empty();
|
|
|
|
|
stack.extend(children.into_iter().map(|child_id| {
|
|
|
|
|
DrawStackEntry::HasNotVisitedChildren(DrawDagEntry {
|
|
|
|
|
activity_id: child_id,
|
|
|
|
|
depth: current_depth.clone(),
|
|
|
|
|
has_later_siblings: true,
|
|
|
|
|
})
|
|
|
|
|
}));
|
|
|
|
|
if has_children {
|
|
|
|
|
stack
|
|
|
|
|
.last_mut()
|
|
|
|
|
.expect("If-statement ensured this is Some()")
|
|
|
|
|
.set_no_later_siblings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DrawStackEntry::VisitedChildren(draw_dag_entry) => {
|
|
|
|
|
draw_order.push(draw_dag_entry);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
draw_order
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_children_in_order(&self, parent_id: u64) -> impl Iterator<Item = u64> {
|
|
|
|
|
let child_ids = self
|
|
|
|
|
.activity_tree
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(move |(_child_id, activity)| activity.get_parent_id() == parent_id)
|
|
|
|
|
.flat_map(|(_child_id, activity)| TransparentIter::new(&self.activity_tree, activity))
|
|
|
|
|
.map(|activity| activity.get_activity_id());
|
|
|
|
|
child_ids
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ActivityState {
|
|
|
|
|
Started {
|
|
|
|
|
progress_numerator: u64,
|
|
|
|
|
progress_denominator: u64,
|
|
|
|
|
progress_running: u64,
|
|
|
|
|
progress_failed: u64,
|
|
|
|
|
},
|
|
|
|
|
Stopped,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for ActivityState {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
ActivityState::Started {
|
|
|
|
|
progress_numerator: 0,
|
|
|
|
|
progress_denominator: 0,
|
|
|
|
|
progress_running: 0,
|
|
|
|
|
progress_failed: 0,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 21:50:08 -05:00
|
|
|
enum DrawStackEntry {
|
|
|
|
|
HasNotVisitedChildren(DrawDagEntry),
|
|
|
|
|
VisitedChildren(DrawDagEntry),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DrawDagEntry {
|
|
|
|
|
activity_id: u64,
|
|
|
|
|
depth: Vec<bool>,
|
|
|
|
|
has_later_siblings: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DrawStackEntry {
|
|
|
|
|
fn set_no_later_siblings(&mut self) -> () {
|
|
|
|
|
match self {
|
|
|
|
|
DrawStackEntry::HasNotVisitedChildren(draw_dag_entry) => {
|
|
|
|
|
draw_dag_entry.has_later_siblings = false
|
|
|
|
|
}
|
|
|
|
|
DrawStackEntry::VisitedChildren(draw_dag_entry) => {
|
|
|
|
|
draw_dag_entry.has_later_siblings = false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PathToRootIter<'tree> {
|
|
|
|
|
activity_tree: &'tree BTreeMap<u64, Activity>,
|
|
|
|
|
next_activity_id: u64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'tree> PathToRootIter<'tree> {
|
|
|
|
|
fn new(
|
|
|
|
|
activity_tree: &'tree BTreeMap<u64, Activity>,
|
|
|
|
|
next_activity_id: u64,
|
|
|
|
|
) -> PathToRootIter<'tree> {
|
|
|
|
|
PathToRootIter {
|
|
|
|
|
activity_tree,
|
|
|
|
|
next_activity_id,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'tree> Iterator for PathToRootIter<'tree> {
|
|
|
|
|
type Item = u64;
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
|
if self.next_activity_id == 0 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let next_activity = self.activity_tree.get(&self.next_activity_id).expect(
|
|
|
|
|
"There shouldn't be a reference to an activity that does not exist in the tree.",
|
|
|
|
|
);
|
|
|
|
|
self.next_activity_id = next_activity.get_parent_id();
|
|
|
|
|
Some(next_activity.get_activity_id())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// An iterator that returns either the original activity if it is not transparent, or if it is transparent, the earliest non-transparent children.
|
|
|
|
|
struct TransparentIter<'tree> {
|
|
|
|
|
activity_tree: &'tree BTreeMap<u64, Activity>,
|
|
|
|
|
parent: &'tree Activity,
|
|
|
|
|
child_index: usize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'tree> TransparentIter<'tree> {
|
|
|
|
|
fn new(
|
|
|
|
|
activity_tree: &'tree BTreeMap<u64, Activity>,
|
|
|
|
|
parent: &'tree Activity,
|
|
|
|
|
) -> TransparentIter<'tree> {
|
|
|
|
|
TransparentIter {
|
|
|
|
|
activity_tree,
|
|
|
|
|
parent,
|
|
|
|
|
child_index: 0,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'tree> Iterator for TransparentIter<'tree> {
|
|
|
|
|
type Item = &'tree Activity;
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
|
if self.child_index == usize::max_value() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
if !self.parent.is_transparent() {
|
|
|
|
|
self.child_index = usize::max_value();
|
|
|
|
|
return Some(self.parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut visible_children_remaining = self.child_index;
|
|
|
|
|
for (_child_id, child) in self.activity_tree.iter() {
|
|
|
|
|
if child.get_parent_id() != self.parent.get_activity_id() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for visible_child in TransparentIter::new(self.activity_tree, child) {
|
|
|
|
|
if visible_children_remaining > 0 {
|
|
|
|
|
visible_children_remaining -= 1;
|
|
|
|
|
} else {
|
|
|
|
|
self.child_index += 1;
|
|
|
|
|
return Some(visible_child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-17 22:49:42 -05:00
|
|
|
#[repr(u8)]
|
|
|
|
|
enum Activity {
|
|
|
|
|
Unknown(ActivityUnknown),
|
|
|
|
|
CopyPath(ActivityCopyPath),
|
|
|
|
|
FileTransfer(ActivityFileTransfer),
|
|
|
|
|
Realize(ActivityRealize),
|
|
|
|
|
CopyPaths(ActivityCopyPaths),
|
|
|
|
|
Builds(ActivityBuilds),
|
|
|
|
|
Build(ActivityBuild),
|
|
|
|
|
OptimizeStore(ActivityOptimizeStore),
|
|
|
|
|
VerifyPaths(ActivityVerifyPaths),
|
|
|
|
|
Substitute(ActivitySubstitute),
|
|
|
|
|
QueryPathInfo(ActivityQueryPathInfo),
|
|
|
|
|
PostBuildHook(ActivityPostBuildHook),
|
|
|
|
|
BuildWaiting(ActivityBuildWaiting),
|
|
|
|
|
FetchTree(ActivityFetchTree),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Activity {
|
|
|
|
|
fn stop(&mut self) -> () {
|
|
|
|
|
match self {
|
|
|
|
|
Activity::Unknown(activity_unknown) => {
|
|
|
|
|
activity_unknown.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::CopyPath(activity_copy_path) => {
|
|
|
|
|
activity_copy_path.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::FileTransfer(activity_file_transfer) => {
|
|
|
|
|
activity_file_transfer.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::Realize(activity_realize) => {
|
|
|
|
|
activity_realize.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::CopyPaths(activity_copy_paths) => {
|
|
|
|
|
activity_copy_paths.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::Builds(activity_builds) => {
|
|
|
|
|
activity_builds.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::Build(activity_build) => {
|
|
|
|
|
activity_build.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::OptimizeStore(activity_optimize_store) => {
|
|
|
|
|
activity_optimize_store.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::VerifyPaths(activity_verify_paths) => {
|
|
|
|
|
activity_verify_paths.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::Substitute(activity_substitute) => {
|
|
|
|
|
activity_substitute.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::QueryPathInfo(activity_query_path_info) => {
|
|
|
|
|
activity_query_path_info.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::PostBuildHook(activity_post_build_hook) => {
|
|
|
|
|
activity_post_build_hook.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::BuildWaiting(activity_build_waiting) => {
|
|
|
|
|
activity_build_waiting.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
Activity::FetchTree(activity_fetch_tree) => {
|
|
|
|
|
activity_fetch_tree.state = ActivityState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
|
|
|
|
|
fn is_active(&self) -> bool {
|
|
|
|
|
match self {
|
|
|
|
|
Activity::Unknown(activity_unknown) => {
|
|
|
|
|
matches!(activity_unknown.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::CopyPath(activity_copy_path) => {
|
|
|
|
|
matches!(activity_copy_path.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::FileTransfer(activity_file_transfer) => {
|
|
|
|
|
matches!(activity_file_transfer.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::Realize(activity_realize) => {
|
|
|
|
|
matches!(activity_realize.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::CopyPaths(activity_copy_paths) => {
|
|
|
|
|
matches!(activity_copy_paths.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::Builds(activity_builds) => {
|
|
|
|
|
matches!(activity_builds.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::Build(activity_build) => {
|
|
|
|
|
matches!(activity_build.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::OptimizeStore(activity_optimize_store) => {
|
|
|
|
|
matches!(activity_optimize_store.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::VerifyPaths(activity_verify_paths) => {
|
|
|
|
|
matches!(activity_verify_paths.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::Substitute(activity_substitute) => {
|
|
|
|
|
matches!(activity_substitute.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::QueryPathInfo(activity_query_path_info) => {
|
|
|
|
|
matches!(
|
|
|
|
|
activity_query_path_info.state,
|
|
|
|
|
ActivityState::Started { .. }
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
Activity::PostBuildHook(activity_post_build_hook) => {
|
|
|
|
|
matches!(
|
|
|
|
|
activity_post_build_hook.state,
|
|
|
|
|
ActivityState::Started { .. }
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
Activity::BuildWaiting(activity_build_waiting) => {
|
|
|
|
|
matches!(activity_build_waiting.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
Activity::FetchTree(activity_fetch_tree) => {
|
|
|
|
|
matches!(activity_fetch_tree.state, ActivityState::Started { .. })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 21:50:08 -05:00
|
|
|
fn is_transparent(&self) -> bool {
|
|
|
|
|
match self {
|
|
|
|
|
Activity::Unknown(_activity_unknown) => false,
|
|
|
|
|
Activity::CopyPath(_activity_copy_path) => false,
|
|
|
|
|
Activity::FileTransfer(_activity_file_transfer) => false,
|
|
|
|
|
Activity::Realize(_activity_realize) => false,
|
|
|
|
|
Activity::CopyPaths(_activity_copy_paths) => false,
|
|
|
|
|
Activity::Builds(_activity_builds) => false,
|
|
|
|
|
Activity::Build(_activity_build) => true,
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 18:39:01 -05:00
|
|
|
fn display_name(&self) -> Option<Cow<'_, str>> {
|
|
|
|
|
match self {
|
|
|
|
|
Activity::Unknown(activity_unknown) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name Unknown");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("Unknown"))
|
|
|
|
|
}
|
|
|
|
|
Activity::CopyPath(activity_copy_path) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name CopyPath");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("CopyPath"))
|
|
|
|
|
}
|
2026-02-21 21:50:08 -05:00
|
|
|
Activity::FileTransfer(activity_file_transfer) => Some(Cow::Owned(format!(
|
|
|
|
|
"FileTransfer({})",
|
|
|
|
|
activity_file_transfer.url
|
|
|
|
|
))),
|
2026-02-19 18:39:01 -05:00
|
|
|
Activity::Realize(activity_realize) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
// TODO what is a good display name for this? Maybe Realize(<parent display name>) ?
|
2026-02-19 18:39:01 -05:00
|
|
|
Some(Cow::Borrowed("Realize"))
|
|
|
|
|
}
|
|
|
|
|
Activity::CopyPaths(activity_copy_paths) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name CopyPaths");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("CopyPaths"))
|
|
|
|
|
}
|
|
|
|
|
Activity::Builds(activity_builds) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name Builds");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("Builds"))
|
|
|
|
|
}
|
|
|
|
|
Activity::Build(activity_build) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
if let Some(machine_name) = &activity_build.machine_name {
|
|
|
|
|
Some(Cow::Owned(format!(
|
|
|
|
|
"Build({}@{machine_name})",
|
|
|
|
|
activity_build.drv_path
|
|
|
|
|
)))
|
|
|
|
|
} else {
|
|
|
|
|
Some(Cow::Owned(format!("Build({})", activity_build.drv_path)))
|
|
|
|
|
}
|
2026-02-19 18:39:01 -05:00
|
|
|
}
|
|
|
|
|
Activity::OptimizeStore(activity_optimize_store) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name OptimizeStore");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("OptimizeStore"))
|
|
|
|
|
}
|
|
|
|
|
Activity::VerifyPaths(activity_verify_paths) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name VerifyPaths");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("VerifyPaths"))
|
|
|
|
|
}
|
|
|
|
|
Activity::Substitute(activity_substitute) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name Substitute");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("Substitute"))
|
|
|
|
|
}
|
|
|
|
|
Activity::QueryPathInfo(activity_query_path_info) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name QueryPathInfo");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("QueryPathInfo"))
|
|
|
|
|
}
|
|
|
|
|
Activity::PostBuildHook(activity_post_build_hook) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name PostBuildHook");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("PostBuildHook"))
|
|
|
|
|
}
|
|
|
|
|
Activity::BuildWaiting(activity_build_waiting) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name BuildWaiting");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("BuildWaiting"))
|
|
|
|
|
}
|
|
|
|
|
Activity::FetchTree(activity_fetch_tree) => {
|
2026-02-21 21:50:08 -05:00
|
|
|
warn!("Unimplemented display_name FetchTree");
|
2026-02-19 18:39:01 -05:00
|
|
|
// TODO
|
|
|
|
|
Some(Cow::Borrowed("FetchTree"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ActivityUnknown {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityCopyPath {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityFileTransfer {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
url: String,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityRealize {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityCopyPaths {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityBuilds {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityBuild {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
2026-02-19 18:39:01 -05:00
|
|
|
drv_path: String,
|
2026-02-21 21:50:08 -05:00
|
|
|
machine_name: Option<String>,
|
2026-02-17 22:49:42 -05:00
|
|
|
}
|
|
|
|
|
struct ActivityOptimizeStore {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityVerifyPaths {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivitySubstitute {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityQueryPathInfo {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityPostBuildHook {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityBuildWaiting {
|
|
|
|
|
id: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
|
|
|
|
struct ActivityFetchTree {
|
|
|
|
|
id: u64,
|
|
|
|
|
parent: u64,
|
|
|
|
|
state: ActivityState,
|
|
|
|
|
}
|
2026-02-21 21:50:08 -05:00
|
|
|
|
|
|
|
|
trait ActivityTreeEntry {
|
|
|
|
|
fn get_activity_id(&self) -> u64;
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ActivityTreeEntry for Activity {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
match self {
|
|
|
|
|
Activity::Unknown(activity_unknown) => activity_unknown.get_activity_id(),
|
|
|
|
|
Activity::CopyPath(activity_copy_path) => activity_copy_path.get_activity_id(),
|
|
|
|
|
Activity::FileTransfer(activity_file_transfer) => {
|
|
|
|
|
activity_file_transfer.get_activity_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::Realize(activity_realize) => activity_realize.get_activity_id(),
|
|
|
|
|
Activity::CopyPaths(activity_copy_paths) => activity_copy_paths.get_activity_id(),
|
|
|
|
|
Activity::Builds(activity_builds) => activity_builds.get_activity_id(),
|
|
|
|
|
Activity::Build(activity_build) => activity_build.get_activity_id(),
|
|
|
|
|
Activity::OptimizeStore(activity_optimize_store) => {
|
|
|
|
|
activity_optimize_store.get_activity_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::VerifyPaths(activity_verify_paths) => activity_verify_paths.get_activity_id(),
|
|
|
|
|
Activity::Substitute(activity_substitute) => activity_substitute.get_activity_id(),
|
|
|
|
|
Activity::QueryPathInfo(activity_query_path_info) => {
|
|
|
|
|
activity_query_path_info.get_activity_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::PostBuildHook(activity_post_build_hook) => {
|
|
|
|
|
activity_post_build_hook.get_activity_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::BuildWaiting(activity_build_waiting) => {
|
|
|
|
|
activity_build_waiting.get_activity_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::FetchTree(activity_fetch_tree) => activity_fetch_tree.get_activity_id(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
match self {
|
|
|
|
|
Activity::Unknown(activity_unknown) => activity_unknown.get_parent_id(),
|
|
|
|
|
Activity::CopyPath(activity_copy_path) => activity_copy_path.get_parent_id(),
|
|
|
|
|
Activity::FileTransfer(activity_file_transfer) => {
|
|
|
|
|
activity_file_transfer.get_parent_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::Realize(activity_realize) => activity_realize.get_parent_id(),
|
|
|
|
|
Activity::CopyPaths(activity_copy_paths) => activity_copy_paths.get_parent_id(),
|
|
|
|
|
Activity::Builds(activity_builds) => activity_builds.get_parent_id(),
|
|
|
|
|
Activity::Build(activity_build) => activity_build.get_parent_id(),
|
|
|
|
|
Activity::OptimizeStore(activity_optimize_store) => {
|
|
|
|
|
activity_optimize_store.get_parent_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::VerifyPaths(activity_verify_paths) => activity_verify_paths.get_parent_id(),
|
|
|
|
|
Activity::Substitute(activity_substitute) => activity_substitute.get_parent_id(),
|
|
|
|
|
Activity::QueryPathInfo(activity_query_path_info) => {
|
|
|
|
|
activity_query_path_info.get_parent_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::PostBuildHook(activity_post_build_hook) => {
|
|
|
|
|
activity_post_build_hook.get_parent_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::BuildWaiting(activity_build_waiting) => {
|
|
|
|
|
activity_build_waiting.get_parent_id()
|
|
|
|
|
}
|
|
|
|
|
Activity::FetchTree(activity_fetch_tree) => activity_fetch_tree.get_parent_id(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ActivityTreeEntry for ActivityUnknown {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityCopyPath {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityFileTransfer {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityRealize {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityCopyPaths {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityBuilds {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityBuild {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityOptimizeStore {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityVerifyPaths {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivitySubstitute {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityQueryPathInfo {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityPostBuildHook {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityBuildWaiting {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
// Parent seems to always be zero?
|
|
|
|
|
0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ActivityTreeEntry for ActivityFetchTree {
|
|
|
|
|
fn get_activity_id(&self) -> u64 {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_parent_id(&self) -> u64 {
|
|
|
|
|
self.parent
|
|
|
|
|
}
|
|
|
|
|
}
|