Skip to content

Commit

Permalink
fix: Improve run task node ID calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 27, 2024
1 parent cb5882b commit 755033b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/action-pipeline/src/job_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct JobContext {
pub result_sender: Sender<Action>,

/// Currently running jobs (used by the dispatcher)
pub running_jobs: Arc<RwLock<FxHashMap<NodeIndex, u32>>>,
pub running_jobs: Arc<RwLock<FxHashMap<NodeIndex, u64>>>,

/// Acquires a permit for concurrency
pub semaphore: Arc<Semaphore>,
Expand Down
25 changes: 12 additions & 13 deletions crates/action/src/action_node.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -30,7 +30,7 @@ pub struct RunTaskNode {
pub persistent: bool, // Never terminates
pub runtime: Runtime,
pub target: Target,
pub id: Option<u32>, // For action graph states
pub id: Option<u64>, // For action graph states
}

impl RunTaskNode {
Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 755033b

Please sign in to comment.