Documentation ¶
Index ¶
Constants ¶
const LoggerTag = "SUPERVISOR"
const ReloaderLoggerTag = "RELOADER"
Variables ¶
This section is empty.
Functions ¶
func ServiceName ¶
ServiceName returns the name of the service. If the service implements the WithName interface, the ServiceName method is used. Otherwise, the name of the type is returned.
Types ¶
type Delayed ¶
type Delayed struct {
// contains filtered or unexported fields
}
Delayed is a service that delays the start of another service.
func NewDelayed ¶
NewDelayed returns a new Delayed service.
type Reloader ¶
type Reloader struct {
// contains filtered or unexported fields
}
Reloader is a service that can reload another wrapped service.
func NewReloader ¶
func NewReloader(cfg ReloaderConfig) *Reloader
NewReloader returns a new Reloader instance.
func (*Reloader) ServiceName ¶
ServiceName implements the supervisor.WithName interface.
type ReloaderConfig ¶
type ReloaderConfig struct { // Factory is a function that creates a new service instance. Every time // the new service is sent to the channel, the service is reloaded with // the new instance. // // The service is stopped when the factory channel is closed or when the // factory function returns an error. Factory func(ctx context.Context, service chan Service) error // Logger is a logger instance. Logger log.Logger }
ReloaderConfig is a configuration for the Reloader service.
type Service ¶
type Service interface { // Start starts the service. Start(ctx context.Context) error // Wait returns a channel that is blocked while service is running. // When the service is stopped, the channel will be closed. If an error // occurs, an error will be sent to the channel before closing it. Wait() <-chan error }
Service that could be managed by Supervisor.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor manages long-running services that implement the Service interface. If any of the managed services fail, all other services are stopped. This ensures that all services are running or none.
func (*Supervisor) Start ¶
func (s *Supervisor) Start(ctx context.Context) error
Start starts all watched services. It can be invoked only once, otherwise it panics.
func (*Supervisor) Wait ¶
func (s *Supervisor) Wait() <-chan error
Wait returns a channel that is blocked until at least one service is running. When all services are stopped, the channel will be closed. If an error occurs in any of the services, it will be sent to the channel before closing it. If multiple service crash, only the first error is returned.
func (*Supervisor) Watch ¶
func (s *Supervisor) Watch(services ...Service)
Watch add one or more services to a supervisor. Services must be added before invoking the Start method, otherwise it panics.