package buildrun import ( "context" "time" mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" "git.novox.be/novox/mesh-sdk/go/seatlist" ) // **No part names the assigner** (design 47 G A-119, A-126, A-131): the module holding the seat mesh-module-assigner is asked of // the seat that places modules through mesh-sdk's seatlist.HolderOf, and the names of the view of its state assignments are made // from it, so a new holder is followed with no change of code. The builder and the checker follow the assignments so. // AssignerHolder is the module holding the seat mesh-module-assigner now, asked until it answers or ctx ends. wait is the pause // between two asks that failed; sleep says false when ctx ended during it. func AssignerHolder(ctx context.Context, call seatlist.HolderCaller, wait time.Duration, sleep func(context.Context, time.Duration) bool, logf func(string, ...any)) (string, bool) { for { holder, err := seatlist.HolderOf(call, mma.Seat) if err == nil { return holder, true } logf("who holds the seat %s is not known yet, so no node is counted by the assignments: %v", mma.Seat, err) if !sleep(ctx, wait) { return "", false } } } // AssignmentsNames are the names made from the holder: the view's first-view tool `.assignments` and the bucket // `_assignments` of the state. type AssignmentsNames struct{ Holder, Tool, Bucket string } // AssignmentsOf is the names of the holder's state assignments. func AssignmentsOf(holder string) AssignmentsNames { return AssignmentsNames{Holder: holder, Tool: holder + "." + mma.StateAssignments, Bucket: holder + "_" + mma.StateAssignments} } // SleepFor waits d, a context's bound, and says whether ctx is still alive. func SleepFor(ctx context.Context, d time.Duration) bool { w, cancel := context.WithTimeout(ctx, d) defer cancel() <-w.Done() return ctx.Err() == nil }