The binary started connectors, module routes, the starter workflow and the worker loops at boot whatever the database said, so an instance with no owner answered operational requests, the bootstrap admin token among them. The governance module now signals once the bootstrap registration has committed, and the composition root holds every operational route, connector and loop back until it does. Liveness stays up and readiness reports the missing owner.
35 lines
905 B
Go
35 lines
905 B
Go
package governance
|
|
|
|
import "sync"
|
|
|
|
// SetupSignal reports that the owner setup transaction has committed. The
|
|
// composition root waits on it instead of polling the database for the change,
|
|
// and it fires once however many callers ask.
|
|
type SetupSignal struct {
|
|
once sync.Once
|
|
done chan struct{}
|
|
}
|
|
|
|
// NewSetupSignal returns a signal for a setup that has not committed yet.
|
|
func NewSetupSignal() *SetupSignal {
|
|
return &SetupSignal{done: make(chan struct{})}
|
|
}
|
|
|
|
// Complete records the commit. A second call, sequential or concurrent,
|
|
// changes nothing. A nil signal is a module built without durable state, as
|
|
// the API document is, and records nothing.
|
|
func (s *SetupSignal) Complete() {
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.once.Do(func() { close(s.done) })
|
|
}
|
|
|
|
// Done is closed once the setup has committed.
|
|
func (s *SetupSignal) Done() <-chan struct{} {
|
|
if s == nil {
|
|
return nil
|
|
}
|
|
return s.done
|
|
}
|