A build machine serves the seat its credential claims (hq ADR 0190, the handover)
After the build role moved to node-build-agent, nothing would hold it until build-agent is registered — and registering build-agent needs a build outcome that only the running builder could produce, bound as it was to the old seat by name. One binary, two roles: the seat a machine serves is the first its credential claims, as the mesh writes the claims beside the credential it issues (ADR 0159); the old builder keeps draining mesh-build-machine, a build-agent takes node-build-agent, and what each says about a build goes out as that seat's events, so an outcome is heard where the asker of that seat listens. A credential naming no claim serves the current role.
This commit is contained in:
@@ -115,9 +115,16 @@ type natsMachine struct {
|
||||
sub *nats.Subscription
|
||||
}
|
||||
|
||||
// MachineOverNATS takes build work from the role this machine holds.
|
||||
// MachineOverNATS takes build work from the current build role.
|
||||
func MachineOverNATS(js *broker.JetStream, on string) BuildMachine {
|
||||
return &natsMachine{js: js, on: on, seat: TheBuildMachine}
|
||||
return MachineOverNATSOn(js, on, TheBuildMachine)
|
||||
}
|
||||
|
||||
// MachineOverNATSOn takes build work from the role named — the one this machine's credential claims
|
||||
// (ADR 0190 handover): its asks come from that seat's worker, and what it says about a build goes
|
||||
// out as that seat's events, so an outcome is heard where the asker listens.
|
||||
func MachineOverNATSOn(js *broker.JetStream, on, seat string) BuildMachine {
|
||||
return &natsMachine{js: js, on: on, seat: seat}
|
||||
}
|
||||
|
||||
func (m *natsMachine) Close() {
|
||||
@@ -194,7 +201,7 @@ func (m *natsMachine) Take(ctx context.Context, do func(context.Context, Build))
|
||||
// the ask to a second machine nor counts the wait against its deliveries.
|
||||
working := make(chan struct{})
|
||||
go stillWorking(msg, working)
|
||||
do(ctx, &natsBuild{request: request, msg: msg, on: m.on, js: m.js})
|
||||
do(ctx, &natsBuild{request: request, msg: msg, on: m.on, js: m.js, seat: m.seat})
|
||||
close(working)
|
||||
}
|
||||
}
|
||||
@@ -205,7 +212,9 @@ type natsBuild struct {
|
||||
msg *nats.Msg
|
||||
on string
|
||||
js *broker.JetStream
|
||||
seq int
|
||||
// seat is the role this build was taken from; what the machine says about it is that role's.
|
||||
seat string
|
||||
seq int
|
||||
}
|
||||
|
||||
func (b *natsBuild) Request() BuildRequest { return b.request }
|
||||
@@ -232,7 +241,7 @@ func (b *natsBuild) Announce(ctx context.Context, result BuildResult) error {
|
||||
}
|
||||
publish, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
if _, err := b.js.Context().Publish(BuildOutcome(), body, nats.Context(publish)); err != nil {
|
||||
if _, err := b.js.Context().Publish(BuildOutcomeOf(b.seat), body, nats.Context(publish)); err != nil {
|
||||
return fmt.Errorf("cannot announce a build's outcome: %w", err)
|
||||
}
|
||||
return nil
|
||||
@@ -252,7 +261,7 @@ func (b *natsBuild) Began(ctx context.Context) error {
|
||||
}
|
||||
publish, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
if _, err := b.js.Context().Publish(BuildStarted(), body, nats.Context(publish)); err != nil {
|
||||
if _, err := b.js.Context().Publish(BuildStartedOf(b.seat), body, nats.Context(publish)); err != nil {
|
||||
return fmt.Errorf("cannot say a build started: %w", err)
|
||||
}
|
||||
return nil
|
||||
@@ -270,7 +279,7 @@ func (b *natsBuild) Say(step, message string) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_ = b.js.Conn().Publish(BuildLog(b.request.ID), body)
|
||||
_ = b.js.Conn().Publish(BuildLogOf(b.seat, b.request.ID), body)
|
||||
}
|
||||
|
||||
func (b *natsBuild) Hold(after time.Duration) error { return b.msg.NakWithDelay(after) }
|
||||
|
||||
Reference in New Issue
Block a user