| Filename | Latest commit message | Latest commit date |
|---|---|---|
Follow-up to the operator's note that an unchecked insert is fine "as long as the builder enforces all invariants". It didn't, so this makes the claim true rather than assumed. check_job_shape now decides everything Graph::insert can reject for a builder-produced node: - UnknownParent / UnknownDep were already impossible -- a handle only exists if this job declared it, and the ids are minted during the insert itself. - DepOutsideParent was not. The grouping rule is now re-derived from the job's own parent chains: a depender parented at `q` may only name a proper descendant of `q` (never `q` itself, which would deadlock), and a depender that declared no parent inherits root_parent -- so with a container every job node qualifies, and without one the target must also be top-level. Mirrors Graph::is_descendant, which starts at the target's parent and so never treats a node as its own ancestor. It also rejects an empty DepWhen, which the graph only catches when validating a deserialized graph (Graph::validate, not insert). Such a node inserts cleanly today and then never becomes runnable -- a silent hang. Refusing it at declaration closes that on the way past. Graph::insert stays the sink. The atomicity comes from the pre-pass being complete, not from bypassing validation, and keeping the graph's own checks means any future drift between the two copies of the grouping rule surfaces as a loud BuildError::Graph instead of silently corrupting the graph -- one branch per node for a backstop. graph_rejection_surfaces_as_is asserted that the graph's rejection surfaced through the builder. That case no longer reaches the graph, so it now pins the stronger property: the error is DepOutsideGroup *and* nothing was inserted. Same for the new empty-edge test. |
||
| .. | ||
| src | ||
| Cargo.toml | ||
| README.md | ||
hive-jobq
A persistent job-DAG scheduler, extracted from hive-c0re's in-tree job_queue
as a domain-agnostic library. It schedules a single persistent graph of
nodes over named resources; it knows nothing about containers, rebuilds, or any
hyperhive type — the node payload N and resource name R are both generic, so
the caller supplies its own domain.
When to use it
Reach for this crate whenever you need to run a DAG of interdependent work items under bounded, named concurrency — the hive-c0re rebuild/lifecycle queue is the first consumer, but nothing here is specific to it. The caller defines the node kinds, wires deps, and supplies a runner; the scheduler decides what can start.
Model
One persistent graph for the whole system, not a DAG per job. Enqueuing inserts a self-contained sub-DAG and returns the ids of the nodes the job asked for, in the order it named them; the scheduler runs a continuous loop, starting every node whose deps are satisfied:
- Resource deps are named counting semaphores over a caller-chosen type
R— e.g.build-slot(capacity N),agent/<name>(capacity 1), or any unconfigured name (capacity 1, created on use). A node acquires all its resource deps atomically at start (all-or-nothing) — no hold-and-wait, so no deadlock. - Node deps wait on another node per
DepWhen:AfterOkneeds success (a failed dep cancels the dependent),AfterAnyonly needs terminal.
A node carries two independent axes: its Deps (ordering + resource needs) and
its parent (structural grouping). The parent chain, not the node edges, is
what the scheduler consults for resource re-entrancy: a resource unit is held
for the acquiring node plus its whole parent subtree, and a descendant needing
a resource an ancestor already holds re-uses that grant (a re-entrant borrow,
one branch at a time) rather than taking a fresh unit.
A NodeId is opaque, stable, and monotonic (safe to persist). The scheduler is
single-threaded — it owns the resource table and mutates it directly.
Shape
Graph<N, R>— the persistent node store.insertmints ids and validates dep/parent references;set_stateis the single state-transition choke point (and where each node's lifecycle timestamps —started_at/finished_at,DateTime<Utc>— are stamped).Node<N, R>—{ id, parent, payload, deps, state, started_at, finished_at, error }. All fields public; derives serde for persistence + the wire.Scheduler<N, R>— drives the graph:settle()starts every ready node (acquiring resources atomically),complete(id, outcome)reports a finished node's result and rolls terminality up the parent chain, releasing grants once a subtree is done.Outcome::{Done, Failed(String)}— the failure reason ridesFailedonto the node'serror.ResourceTable<R>— per-name capacities; unconfigured names default to capacity 1.
See the crate-root and scheduler module //! docs for the full borrow/release
model.