From 0719c3264a617d12e0906262943e20086657f74e Mon Sep 17 00:00:00 2001 From: Jacob LeGrone Date: Wed, 4 Aug 2021 15:13:47 -0400 Subject: [PATCH] allow passing additional options when configuring client --- server/server.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/server/server.go b/server/server.go index c93ab5c0..fd76998e 100644 --- a/server/server.go +++ b/server/server.go @@ -94,7 +94,7 @@ func (s *Server) Start() error { // Wait for each namespace to be ready for _, ns := range s.config.Namespaces { - c, err := s.newClient(context.Background(), ns) + c, err := s.newClient(context.Background(), client.Options{Namespace: ns}) if err != nil { panic(err) } @@ -136,20 +136,33 @@ func (s *Server) Stop() { s.internal.Stop() } +// NewClient initializes a client ready to communicate with the Temporal +// server in the target namespace. func (s *Server) NewClient(ctx context.Context, namespace string) (client.Client, error) { + return s.newClientBlocking(ctx, client.Options{Namespace: namespace}) +} + +// NewClientWithOptions is the same as NewClient but allows further customization. +// +// To set the client's namespace, use the corresponding field in client.Options. +// +// Note that the HostPort and ConnectionOptions fields of client.Options will always be overridden. +func (s *Server) NewClientWithOptions(ctx context.Context, options client.Options) (client.Client, error) { + return s.newClientBlocking(ctx, options) +} + +func (s *Server) newClientBlocking(ctx context.Context, options client.Options) (client.Client, error) { s.setupWaitGroup.Wait() - return s.newClient(ctx, namespace) + return s.newClient(ctx, options) } -func (s *Server) newClient(ctx context.Context, namespace string) (client.Client, error) { - return client.NewClient(client.Options{ - Namespace: namespace, - HostPort: s.frontendHostPort, - ConnectionOptions: client.ConnectionOptions{ - DisableHealthCheck: false, - HealthCheckTimeout: timeoutFromContext(ctx, time.Minute), - }, - }) +func (s *Server) newClient(ctx context.Context, options client.Options) (client.Client, error) { + options.HostPort = s.frontendHostPort + options.ConnectionOptions = client.ConnectionOptions{ + DisableHealthCheck: false, + HealthCheckTimeout: timeoutFromContext(ctx, time.Minute), + } + return client.NewClient(options) } func (s *Server) newNamespaceClient(ctx context.Context) (client.NamespaceClient, error) {