diff --git a/multi/parameters.go b/multi/parameters.go index 070933c8..0a64c386 100644 --- a/multi/parameters.go +++ b/multi/parameters.go @@ -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. @@ -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) { diff --git a/multi/service.go b/multi/service.go index bde1ad78..566f278a 100644 --- a/multi/service.go +++ b/multi/service.go @@ -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)) diff --git a/multi/service_test.go b/multi/service_test.go index 0a157aec..8f6ee560 100644 --- a/multi/service_test.go +++ b/multi/service_test.go @@ -57,7 +57,7 @@ func TestService(t *testing.T) { inactiveconsensusclient, }), }, - err: "no providers active, cannot proceed", + err: "client is not active", }, { name: "Good",