supervisor

package
v0.22.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "SUPERVISOR"

Variables

This section is empty.

Functions

func ServiceName added in v0.20.0

func ServiceName(s any) string

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 Config added in v0.11.0

type Config interface {
	Services(logger log.Logger, appName string, appVersion string) (Service, error)
}

type Delayed added in v0.10.0

type Delayed struct {
	// contains filtered or unexported fields
}

Delayed is a service that delays the start of another service.

func NewDelayed added in v0.10.0

func NewDelayed(service Service, delay time.Duration) *Delayed

NewDelayed returns a new Delayed service.

func (*Delayed) Start added in v0.10.0

func (d *Delayed) Start(ctx context.Context) error

Start implements the Service interface.

func (*Delayed) Wait added in v0.10.0

func (d *Delayed) Wait() <-chan error

Wait implements the Service interface.

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 New

func New(logger log.Logger) *Supervisor

New returns a new instance of *Supervisor.

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.

type WithName added in v0.20.0

type WithName interface {
	Service

	ServiceName() string
}

WithName is an optional interface that can be implemented by a service to provide a name. The name is used in logs and metrics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL