From 91192860f6a2d41eff9ae05d5b581731c59d6676 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 27 Nov 2024 15:43:25 -0800 Subject: [PATCH] fix: Improve run task node ID calculation. --- crates/action-pipeline/src/job_context.rs | 2 +- crates/action/src/action_node.rs | 25 +++++++++++------------ crates/app/src/commands/ci.rs | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/crates/action-pipeline/src/job_context.rs b/crates/action-pipeline/src/job_context.rs index d78065303b2..9e579317b7e 100644 --- a/crates/action-pipeline/src/job_context.rs +++ b/crates/action-pipeline/src/job_context.rs @@ -26,7 +26,7 @@ pub struct JobContext { pub result_sender: Sender, /// Currently running jobs (used by the dispatcher) - pub running_jobs: Arc>>, + pub running_jobs: Arc>>, /// Acquires a permit for concurrency pub semaphore: Arc, diff --git a/crates/action/src/action_node.rs b/crates/action/src/action_node.rs index 593e33e28e0..310d771a3bc 100644 --- a/crates/action/src/action_node.rs +++ b/crates/action/src/action_node.rs @@ -1,7 +1,7 @@ use moon_common::Id; use moon_target::Target; use moon_toolchain::Runtime; -use rustc_hash::FxHashMap; +use rustc_hash::{FxHashMap, FxHasher}; use serde::Serialize; use std::hash::{Hash, Hasher}; @@ -30,7 +30,7 @@ pub struct RunTaskNode { pub persistent: bool, // Never terminates pub runtime: Runtime, pub target: Target, - pub id: Option, // For action graph states + pub id: Option, // For action graph states } impl RunTaskNode { @@ -47,21 +47,20 @@ impl RunTaskNode { } fn calculate_id(&mut self) { - let mut id = 0; + let mut hasher = FxHasher::default(); + hasher.write(self.target.as_str().as_bytes()); - for ch in self.target.as_str().chars() { - if let Some(num) = ch.to_digit(10) { - id += num; - } + if self.persistent { + hasher.write_u8(100); } - if self.persistent { - id += 100; - } else if self.interactive { - id += 50; + if self.interactive { + hasher.write_u8(50); } - self.id = Some(id); + self.id = Some(hasher.finish()); + + dbg!(self.target.as_str(), self.id.as_ref()); } } @@ -117,7 +116,7 @@ impl ActionNode { Self::SyncWorkspace } - pub fn get_id(&self) -> u32 { + pub fn get_id(&self) -> u64 { match self { Self::RunTask(inner) => inner.id.unwrap_or_default(), _ => 0, diff --git a/crates/app/src/commands/ci.rs b/crates/app/src/commands/ci.rs index ee3ff5a360a..78255226180 100644 --- a/crates/app/src/commands/ci.rs +++ b/crates/app/src/commands/ci.rs @@ -214,7 +214,7 @@ async fn generate_action_graph( let mut action_graph_builder = session.build_action_graph(workspace_graph).await?; action_graph_builder.set_touched_files(touched_files)?; - action_graph_builder.set_affected_scopes(UpstreamScope::Direct, DownstreamScope::Direct)?; + action_graph_builder.set_affected_scopes(UpstreamScope::Direct, DownstreamScope::Deep)?; // Run dependents to ensure consumers still work correctly action_graph_builder.run_from_requirements(RunRequirements {