Skip to content

Commit

Permalink
Provide allowDelayedStart() for multi
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Mar 5, 2024
1 parent b62ba85 commit 48c9750
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
22 changes: 15 additions & 7 deletions multi/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
)

type parameters struct {
logLevel zerolog.Level
monitor metrics.Service
clients []consensusclient.Service
addresses []string
timeout time.Duration
extraHeaders map[string]string
enforceJSON bool
logLevel zerolog.Level
monitor metrics.Service
clients []consensusclient.Service
addresses []string
timeout time.Duration
extraHeaders map[string]string
enforceJSON bool
allowDelayedStart bool
}

// Parameter is the interface for service parameters.
Expand Down Expand Up @@ -85,6 +86,13 @@ func WithEnforceJSON(enforceJSON bool) Parameter {
})
}

// WithAllowDelayedStart allows the service to start even if the client is unavailable.
func WithAllowDelayedStart(allowDelayedStart bool) Parameter {
return parameterFunc(func(p *parameters) {
p.allowDelayedStart = allowDelayedStart
})
}

// WithExtraHeaders sets additional headers to be sent with each HTTP request.
func WithExtraHeaders(headers map[string]string) Parameter {
return parameterFunc(func(p *parameters) {
Expand Down
4 changes: 2 additions & 2 deletions multi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func New(ctx context.Context, params ...Parameter) (consensusclient.Service, err
setProviderStateMetric(ctx, client.Address(), "inactive")
}
}
if len(activeClients) == 0 {
return nil, errors.New("no providers active, cannot proceed")
if len(activeClients) == 0 && !parameters.allowDelayedStart {
return nil, consensusclient.ErrNotActive
}
log.Trace().Int("active", len(activeClients)).Int("inactive", len(inactiveClients)).Msg("Initial providers")
setConnectionsMetric(ctx, len(activeClients), len(inactiveClients))
Expand Down
2 changes: 1 addition & 1 deletion multi/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestService(t *testing.T) {
inactiveconsensusclient,
}),
},
err: "no providers active, cannot proceed",
err: "client is not active",
},
{
name: "Good",
Expand Down

0 comments on commit 48c9750

Please sign in to comment.