Documentation
¶
Index ¶
- Variables
- func ResetInstance()
- type AllowedFailure
- type AllowedFailureMockService
- type Dependent
- type DependentMockService
- type FullMockService
- func (f *FullMockService) Dependencies() []string
- func (f *FullMockService) IsAllowedFailure() bool
- func (f *FullMockService) MaxRetries() int
- func (f *FullMockService) RetryDelay() time.Duration
- func (f *FullMockService) WithAllowFailure(v bool) *FullMockService
- func (f *FullMockService) WithDependencies(deps ...string) *FullMockService
- func (f *FullMockService) WithMaxRetries(n int) *FullMockService
- func (f *FullMockService) WithRetryDelay(d time.Duration) *FullMockService
- type MockService
- func (m *MockService) IsRunning() bool
- func (m *MockService) Name() string
- func (m *MockService) Run(ctx context.Context) error
- func (m *MockService) RunCount() int
- func (m *MockService) Stop(_ context.Context) error
- func (m *MockService) WasRunCalled() bool
- func (m *MockService) WasStopCalled() bool
- func (m *MockService) WithOnRun(fn func()) *MockService
- func (m *MockService) WithRunDelay(delay time.Duration) *MockService
- func (m *MockService) WithRunError(err error) *MockService
- func (m *MockService) WithRunErrors(errs ...error) *MockService
- func (m *MockService) WithStopError(err error) *MockService
- type ReadyMockService
- type ReadyNotifier
- type Retryable
- type RetryableMockService
- type Service
- type ServiceManager
- type TestService
Constants ¶
This section is empty.
Variables ¶
var ( ErrServiceNotFound = errors.New("service not found") ErrNoEnabledServices = errors.New("no enabled services") ErrCyclicDependency = errors.New("cyclic dependency detected") ErrDependencyNotFound = errors.New("dependency not found") ErrMaxRetriesReached = errors.New("max retries reached") ErrStopTimeout = errors.New("service stop timed out") ErrServicePanic = errors.New("service panicked") )
Functions ¶
func ResetInstance ¶
func ResetInstance()
Types ¶
type AllowedFailure ¶
type AllowedFailure interface {
IsAllowedFailure() bool
}
AllowedFailure is optionally implemented by services whose failure should not bring down the entire service manager.
type AllowedFailureMockService ¶
type AllowedFailureMockService struct {
*MockService
}
func NewAllowedFailureMockService ¶
func NewAllowedFailureMockService( name string, ) *AllowedFailureMockService
func (*AllowedFailureMockService) IsAllowedFailure ¶
func (a *AllowedFailureMockService) IsAllowedFailure() bool
type Dependent ¶
type Dependent interface {
Dependencies() []string
}
Dependent is optionally implemented by services that must start after other services. Dependencies returns the names of services this service depends on.
type DependentMockService ¶
type DependentMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewDependentMockService ¶
func NewDependentMockService( name string, deps ...string, ) *DependentMockService
func (*DependentMockService) Dependencies ¶
func (d *DependentMockService) Dependencies() []string
type FullMockService ¶
type FullMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewFullMockService ¶
func NewFullMockService(name string) *FullMockService
func (*FullMockService) Dependencies ¶
func (f *FullMockService) Dependencies() []string
func (*FullMockService) IsAllowedFailure ¶
func (f *FullMockService) IsAllowedFailure() bool
func (*FullMockService) MaxRetries ¶
func (f *FullMockService) MaxRetries() int
func (*FullMockService) RetryDelay ¶
func (f *FullMockService) RetryDelay() time.Duration
func (*FullMockService) WithAllowFailure ¶
func (f *FullMockService) WithAllowFailure( v bool, ) *FullMockService
func (*FullMockService) WithDependencies ¶
func (f *FullMockService) WithDependencies( deps ...string, ) *FullMockService
func (*FullMockService) WithMaxRetries ¶
func (f *FullMockService) WithMaxRetries( n int, ) *FullMockService
func (*FullMockService) WithRetryDelay ¶
func (f *FullMockService) WithRetryDelay( d time.Duration, ) *FullMockService
type MockService ¶
type MockService struct {
// contains filtered or unexported fields
}
func NewMockService ¶
func NewMockService(name string) *MockService
func (*MockService) IsRunning ¶
func (m *MockService) IsRunning() bool
func (*MockService) Name ¶
func (m *MockService) Name() string
func (*MockService) RunCount ¶
func (m *MockService) RunCount() int
func (*MockService) WasRunCalled ¶
func (m *MockService) WasRunCalled() bool
func (*MockService) WasStopCalled ¶
func (m *MockService) WasStopCalled() bool
func (*MockService) WithOnRun ¶
func (m *MockService) WithOnRun( fn func(), ) *MockService
func (*MockService) WithRunDelay ¶
func (m *MockService) WithRunDelay( delay time.Duration, ) *MockService
func (*MockService) WithRunError ¶
func (m *MockService) WithRunError( err error, ) *MockService
func (*MockService) WithRunErrors ¶
func (m *MockService) WithRunErrors( errs ...error, ) *MockService
func (*MockService) WithStopError ¶
func (m *MockService) WithStopError( err error, ) *MockService
type ReadyMockService ¶ added in v1.0.2
type ReadyMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewReadyMockService ¶ added in v1.0.2
func NewReadyMockService( name string, deps ...string, ) *ReadyMockService
func (*ReadyMockService) Dependencies ¶ added in v1.0.2
func (r *ReadyMockService) Dependencies() []string
func (*ReadyMockService) Ready ¶ added in v1.0.2
func (r *ReadyMockService) Ready() <-chan struct{}
func (*ReadyMockService) SignalReady ¶ added in v1.0.2
func (r *ReadyMockService) SignalReady()
type ReadyNotifier ¶ added in v1.0.2
type ReadyNotifier interface {
Ready() <-chan struct{}
}
ReadyNotifier is optionally implemented by services that need to signal when they're actually ready to serve. The service manager waits for the Ready channel to close before starting dependent services. Services that don't implement this are considered ready immediately after their goroutine is launched.
type Retryable ¶
Retryable is optionally implemented by services that want automatic restart on failure. MaxRetries returns the maximum number of retry attempts (0 means no retries). RetryDelay returns the delay between retries. Use human-readable durations like 1s, 2m, 1h30m via time.Duration.
type RetryableMockService ¶
type RetryableMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewRetryableMockService ¶
func NewRetryableMockService( name string, maxRetries int, ) *RetryableMockService
func (*RetryableMockService) MaxRetries ¶
func (r *RetryableMockService) MaxRetries() int
func (*RetryableMockService) RetryDelay ¶
func (r *RetryableMockService) RetryDelay() time.Duration
func (*RetryableMockService) WithRetryDelay ¶
func (r *RetryableMockService) WithRetryDelay( d time.Duration, ) *RetryableMockService
type ServiceManager ¶
type ServiceManager struct {
// contains filtered or unexported fields
}
func GetInstance ¶
func GetInstance() *ServiceManager
func (*ServiceManager) Add ¶
func (s *ServiceManager) Add(services ...Service)
func (*ServiceManager) ClearServices ¶
func (s *ServiceManager) ClearServices()
func (*ServiceManager) Stop ¶
func (s *ServiceManager) Stop(ctx context.Context)
type TestService ¶
type TestService struct {
// contains filtered or unexported fields
}
func NewTestService ¶
func NewTestService(name string) *TestService
func (*TestService) Name ¶
func (s *TestService) Name() string