Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
allow passing additional options when configuring client
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrone committed Aug 4, 2021
1 parent f81b595 commit 0719c32
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0719c32

Please sign in to comment.