Skip to content

Commit

Permalink
Improve consistency for Egress/Ingress client constructors (#526)
Browse files Browse the repository at this point in the history
Other psrpc clients are using this syntax to set logger, default timeouts/etc
  • Loading branch information
davidzhao authored Nov 28, 2023
1 parent fd70665 commit 61e6462
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
20 changes: 13 additions & 7 deletions rpc/egress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ type egressClient struct {
EgressHandlerClient
}

func NewEgressClient(bus psrpc.MessageBus) (EgressClient, error) {
if bus == nil {
func NewEgressClient(params ClientParams) (EgressClient, error) {
if params.Bus == nil {
return nil, nil
}

internalClient, err := NewEgressInternalClient(bus, middleware.WithRPCRetries(middleware.RetryOptions{
MaxAttempts: retries,
Timeout: time.Second * 10,
opts := clientOptions(params)
timeout := params.Timeout
if timeout < 10*time.Second {
timeout = 10 * time.Second
}
internalOpts := append(opts, middleware.WithRPCRetries(middleware.RetryOptions{
MaxAttempts: params.MaxAttempts,
// use longer retry timeout
Timeout: timeout,
IsRecoverable: func(err error) bool {
var e psrpc.Error
if !errors.As(err, &e) {
Expand All @@ -54,11 +59,12 @@ func NewEgressClient(bus psrpc.MessageBus) (EgressClient, error) {
e.Code() == psrpc.Unavailable
},
}))
internalClient, err := NewEgressInternalClient(params.Bus, internalOpts...)
if err != nil {
return nil, err
}

handlerClient, err := NewEgressHandlerClient(bus)
handlerClient, err := NewEgressHandlerClient(params.Bus, opts...)
if err != nil {
return nil, err
}
Expand Down
13 changes: 5 additions & 8 deletions rpc/ingress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

package rpc

import (
"github.com/livekit/psrpc"
)

type IngressClient interface {
IngressInternalClient
IngressHandlerClient
Expand All @@ -28,16 +24,17 @@ type ingressClient struct {
IngressHandlerClient
}

func NewIngressClient(bus psrpc.MessageBus) (IngressClient, error) {
if bus == nil {
func NewIngressClient(params ClientParams) (IngressClient, error) {
if params.Bus == nil {
return nil, nil
}
opts := clientOptions(params)

internalClient, err := NewIngressInternalClient(bus)
internalClient, err := NewIngressInternalClient(params.Bus, opts...)
if err != nil {
return nil, err
}
handlerClient, err := NewIngressHandlerClient(bus)
handlerClient, err := NewIngressHandlerClient(params.Bus, opts...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 61e6462

Please sign in to comment.