Documentation ¶
Index ¶
Constants ¶
const LoggerTag = "SUPERVISOR"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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.