ChildTemplate

@Serializable
data class ChildTemplate(val weight: Weight, val maxConcurrent: Long? = null, @IntroducedAt(version = "0.7.7") val template: Topology.ChildTemplate? = null)

A group's template for the children the consumer attaches to it while running (LocalHeddle.attach). Every attached child gets weight and maxConcurrent. Its name is an opaque string the consumer chooses: heddle attaches no meaning to it.

With a template of its own, each attached child is a group: the consumer attaches children beneath it, each getting what that template gives, and the attached child itself is never leased. Templates nest as deep as the consumer's tree does: kind → repository → author is a declared kind whose template's template is the authors'. Weights are per template, so every repository weighs the same beside its siblings, and every author beside the other authors of its repository.

Samples

val ci = draft("ci") {
    group("repos", maxConcurrent = 2) { template(maxConcurrent = 1) }
    lane("nightly")
}
val (heddle, booted) = LocalHeddle.fromTopology(ci, LocalPolicy(defaultReservation = 1L), epoch = 0L)
check(booted.refusals.isEmpty())
heddle.reconcileCapacity(totalSlots = 4L)
val (a, b, c) = listOf("a", "b", "c").mapIndexed { i, name ->
    check(heddle.attach(listOf("repos"), name, generation = i + 1L).refusals.isEmpty())
    ci.attachedChildId(listOf("repos"), name)
}
val nightly = ci.groupId("nightly")
val all = setOf(a, b, c, nightly)

// `a` runs one job, its own ceiling.
check((heddle.acquire(setOf(a), setOf(a), startedAt = 0L) as AcquireOutcome.Acquired).lease.leaf == a)
check(heddle.explain(a, waiting = all, eligible = all) == WaitExplanation.AtCeiling(a, limit = 1L))
// `b` runs one too, which puts the group at its ceiling of two: `c` waits on the group.
check((heddle.acquire(setOf(b), setOf(b), startedAt = 0L) as AcquireOutcome.Acquired).lease.leaf == b)
check(heddle.explain(c, waiting = all, eligible = all) == WaitExplanation.AtCeiling(ci.groupId("repos"), limit = 2L))
// So the next slot goes to the nightly lane, however much the repositories have queued.
check((heddle.acquire(all, all, startedAt = 1L) as AcquireOutcome.Acquired).lease.leaf == nightly)
val ci = draft("ci") {
    // Each repository weighs 2 beside the nightly lane, and each author caps at one job.
    group("repos") { template(Weight.of(2), template = Topology.ChildTemplate(Weight.ONE, maxConcurrent = 1L)) }
    lane("nightly")
}
val (heddle, booted) = LocalHeddle.fromTopology(ci, LocalPolicy(defaultReservation = 1L), epoch = 0L)
check(booted.refusals.isEmpty())
heddle.reconcileCapacity(totalSlots = 4L)

// Attaching an author attaches its repository too, in the same unit.
val kuilt = GroupPath.Attached(listOf("repos"), "kuilt")
val alice = GroupPath.Nested(kuilt, "alice")
check(heddle.attach(alice, generation = 1L).refusals.isEmpty())
val aliceId = checkNotNull(ci.findGroupId(alice))
check(aliceId == GroupId("ci/repos/!kuilt/!alice") && ci.findPath(aliceId) == alice)

// Work is charged to the author; the repository itself is never leased.
val kuiltId = checkNotNull(ci.findGroupId(kuilt))
check(heddle.admit(kuiltId, waiting = setOf(kuiltId), startedAt = 0L) == AcquireOutcome.NoLiveLineage(kuiltId))
val lease = (heddle.acquire(setOf(aliceId), setOf(aliceId), startedAt = 0L) as AcquireOutcome.Acquired).lease
check(lease.leaf == aliceId)

// Detaching the repository closes alice too, and waits for her running job.
val detached = heddle.detach(kuilt)
check(detached.refusals.isNotEmpty() && detached.refusals.all { it is StepRefusal.Draining })
check(heddle.complete(lease.id, actualCost = 1L, waiting = emptySet()) is LeaseOutcome.Done)
check(heddle.detach(kuilt).refusals.isEmpty())

Constructors

Link copied to clipboard
constructor(weight: Weight, maxConcurrent: Long? = null, @IntroducedAt(version = "0.7.7") template: Topology.ChildTemplate? = null)

Properties

Link copied to clipboard

the most leases open on each attached child at once, not on all of them together; null for no ceiling, 0 to pause every one. Never negative. The group's own Group.maxConcurrent caps them all together. On a template with a template, it caps all the leases beneath each attached child together.

Link copied to clipboard

what each child attached beneath an attached child gets, or null when every attached child is a leaf. A snapshot written before this field existed decodes as null, and a null one is left out of the encoding, so those bytes do not change.

Link copied to clipboard

each attached child's share relative to its siblings, declared or attached.