diff --git a/hive-c0re/src/job_queue/mod.rs b/hive-c0re/src/job_queue/mod.rs index bbe90925..0f0bc009 100644 --- a/hive-c0re/src/job_queue/mod.rs +++ b/hive-c0re/src/job_queue/mod.rs @@ -170,7 +170,11 @@ fn insert_group( let mut ids: Vec = Vec::with_capacity(nodes.len()); for ns in nodes { let payload = ns.kind.clone(); - let mut deps = payload.resource_deps(); + let mut deps: Vec> = payload + .resource_deps() + .into_iter() + .map(|(name, count)| Dep::Resource { name, count }) + .collect(); for d in &ns.deps { deps.push(Dep::Node { id: ids[dep_index(d.on)], @@ -450,17 +454,14 @@ impl JobQueue { .nodes() .filter(|n| matches!(n.state, State::Running)) .filter_map(|n| { - let agent = n - .payload - .resource_deps() - .into_iter() - .find_map(|d| match d { - Dep::Resource { - name: Resource::Agent(a), - .. - } => Some(a), - _ => None, - })?; + let agent = + n.payload + .resource_deps() + .into_iter() + .find_map(|(name, _)| match name { + Resource::Agent(a) => Some(a), + _ => None, + })?; Some(RunningTransient { agent, label: n.payload.as_str().to_owned(), diff --git a/hive-c0re/src/job_queue/resource.rs b/hive-c0re/src/job_queue/resource.rs index 0b46ab9d..a3118137 100644 --- a/hive-c0re/src/job_queue/resource.rs +++ b/hive-c0re/src/job_queue/resource.rs @@ -4,8 +4,6 @@ //! payload `N`; here `R` is [`Resource`] and `N` is [`NodeKind`] directly (each //! variant carries the agent it targets). -use hive_jobq::Dep; - use super::model::NodeKind; /// The two resource classes the queue gates concurrency on, as the crate's @@ -36,7 +34,7 @@ pub enum Resource { } impl NodeKind { - /// The [`Dep::Resource`] edges this node must acquire to run, derived from + /// The resources this node must acquire to run — `(name, units)` — derived from /// its kind + agent: a build slot for nix-heavy kinds /// ([`NodeKind::needs_build_slot`]) and the agent lease for /// container-affecting kinds ([`NodeKind::needs_lease`]). Lease-exempt @@ -50,25 +48,16 @@ impl NodeKind { /// (`try_acquire_all`) — a node never holds one resource while waiting on /// another, so the multi-resource kinds (a `MetaLock` wants a build slot /// *and* the meta window) cannot deadlock against each other. - pub fn resource_deps(&self) -> Vec> { + pub fn resource_deps(&self) -> Vec<(Resource, u32)> { let mut deps = Vec::new(); if self.needs_build_slot() { - deps.push(Dep::Resource { - name: Resource::BuildSlot, - count: 1, - }); + deps.push((Resource::BuildSlot, 1)); } if self.needs_lease() { - deps.push(Dep::Resource { - name: Resource::Agent(self.agent().to_owned()), - count: 1, - }); + deps.push((Resource::Agent(self.agent().to_owned()), 1)); } if self.needs_meta_window() { - deps.push(Dep::Resource { - name: Resource::MetaWindow, - count: 1, - }); + deps.push((Resource::MetaWindow, 1)); } deps }