41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package check
|
|
|
|
import "sync"
|
|
|
|
// PlansBuildingBucket is the controller's bucket of the delivery plans in their build phase, one key for each plan, written
|
|
// by the controller alone (issue 1652): a plan key there means a delivery builds on the build nodes, and no new check starts
|
|
// meanwhile (ADR 0484 clause 12, ADR 0483 clause 6). The bucket may be absent: the controller's issue 1652 is delivered
|
|
// before R4c-5b, and if it is not, the bucket is read as empty.
|
|
const PlansBuildingBucket = "mesh-controller_plans-building"
|
|
|
|
// PlanHold holds which delivery plans build now, from the controller's bucket (a watch puts the changes in). Safe for use
|
|
// from the watch and from a check at once.
|
|
type PlanHold struct {
|
|
mu sync.Mutex
|
|
plans map[string]bool
|
|
}
|
|
|
|
// Put takes a change of the bucket in: a put of a plan's key, or its delete. It answers whether a delivery builds now
|
|
// differently than before, so a watch wakes the checker when the last plan ended.
|
|
func (h *PlanHold) Put(key string, deleted bool) (changed bool) {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
before := len(h.plans) > 0
|
|
if deleted {
|
|
delete(h.plans, key)
|
|
} else {
|
|
if h.plans == nil {
|
|
h.plans = map[string]bool{}
|
|
}
|
|
h.plans[key] = true
|
|
}
|
|
return before != (len(h.plans) > 0)
|
|
}
|
|
|
|
// Held says whether any delivery plan builds now.
|
|
func (h *PlanHold) Held() bool {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
return len(h.plans) > 0
|
|
}
|