Files
archie/internal/app/servicekit/statestore.go
T
sam 794c7ac8c6 fix(services): services wait for peers instead of exiting; restarted broker keeps its endpoint
State Store calls from the daemon, Gateway and Messaging wait for the store to
come up, so start order no longer matters; the daemon's state_db probe carries
its own deadline so an outage reports degraded instead of hanging. The
Gateway retries its first NATS connect. A restarted daemon reuses the embedded
broker's previous port and token, so the Gateway reconnects instead of
holding a dead address. Fixes a nil catalog the catalog move introduced.
2026-10-04 01:15:11 +10:00

28 lines
1.2 KiB
Go

package servicekit
import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/secret"
"google.golang.org/grpc"
)
// StateStoreClient dials the State Store gRPC service the daemon's own
// capture/mapping/binding consumers call. Token resolution is the daemon's
// (it owns the config keys and the secret registry); the dial itself and the
// fail-closed non-loopback rule belong to the transport, so they come
// from staterpc.Dial. Calls wait for the State Store rather than fail while it
// is down, so boot order between services does not matter.
func StateStoreClient(services config.Services, secrets *secret.Registry) (*staterpc.Client, func(), error) {
target, err := services.RequireTarget(config.ServiceNameState)
if err != nil {
return nil, nil, err
}
return staterpc.Dial(target, services.ResolvedToken(config.ServiceNameState, secrets.Getenv), WaitForPeer)
}
// WaitForPeer makes a service's calls to another service wait for it to come
// up instead of failing while it is down or restarting. A call that must not
// wait carries its own deadline.
var WaitForPeer = grpc.WithDefaultCallOptions(grpc.WaitForReady(true))