refactor(job-queue): let resource_deps say (resource, units)
It never produced a `Dep::Node`, so returning `Vec<Dep<Resource>>` made every caller match a variant that cannot occur. `running_transients` paid for it with a two-arm match to pull the agent out of a lease edge. `Vec<(Resource, u32)>` says the same thing in the type, and is what the job builder's `.needs_units(name, count)` takes — the insertion path wraps it back into a `Dep::Resource` at the one place that still speaks in edges.
This commit is contained in:
parent
f161f8e40f
commit
9be7731c5e
2 changed files with 18 additions and 28 deletions
|
|
@ -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<Dep<Resource>> {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue