supervisor

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusStopped  int32 = iota
	StatusStarting int32 = iota
	StatusRunning  int32 = iota
	StatusStopping int32 = iota
)

StatusTypes

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecSubprocess

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

ExecSubprocess is a subprocess that is implemented using `os/exec`.

func (ExecSubprocess) Pid

func (esp ExecSubprocess) Pid() int

Pid returns the underlying pid.

func (ExecSubprocess) Signal

func (esp ExecSubprocess) Signal(sig syscall.Signal) error

func (ExecSubprocess) Start

func (esp ExecSubprocess) Start() error

Start invokes the subprocess.

func (ExecSubprocess) Wait

func (esp ExecSubprocess) Wait() error

Wait blocks on the subprocess.

type ExecSubprocessProvider

type ExecSubprocessProvider struct{}

ExecSubprocessProvider is the exec subprocess provider.

func (ExecSubprocessProvider) Exec

type Exit

type Exit struct {
	Timestamp time.Time
	Error     error
}

Exit is a time and a error associated with a service exiting.

type FileEventProvider

type FileEventProvider interface {
	Notify(string, chan notify.EventInfo) error
}

FileEventProvider handles hooking up file event notifications.

type MockNotifyProvider

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

MockNotifyProvider is a mocked notify provider.

func (*MockNotifyProvider) Notify

func (mnp *MockNotifyProvider) Notify(watchedPath string, fsevents chan notify.EventInfo) error

Notify calls the underlying notification implemention.

func (*MockNotifyProvider) Signal

func (mnp *MockNotifyProvider) Signal(event notify.EventInfo)

Signal sends an event to the channel.

type MockSubprocess

type MockSubprocess interface {
	Subprocess
	Exit(error)
}

MockSubprocess is a mocked subprocess.

type MockSubprocessProvider

type MockSubprocessProvider struct{}

MockSubprocessProvider is a provider for subprocesses that returns a mocked subprocess.

func (MockSubprocessProvider) Exec

Exec returns a new mocked subprocess.

type NotifyProvider

type NotifyProvider struct{}

NotifyProvider is the concrete notify provider.

func (NotifyProvider) Notify

func (np NotifyProvider) Notify(watchedPath string, fsevents chan notify.EventInfo) error

Notify calls the underlying notification implemention.

type PrefixWriter

type PrefixWriter struct {
	Prefix string
	Writer io.Writer
}

func (PrefixWriter) Write

func (pw PrefixWriter) Write(data []byte) (int, error)

type RestartPolicy

type RestartPolicy interface {
	ShouldRestart(context.Context, *ServiceHistory) bool
	Delay(context.Context, *ServiceHistory) time.Duration
}

RestartPolicy is a type that accepts a service history and returns answers to common questions.

func RestartPolicySuccessiveFailures

func RestartPolicySuccessiveFailures(successiveFailures int) RestartPolicy

RestartPolicySuccessiveFailures is a restart policy that will allow the process to restart some number of times on error, after which the supervisor will exit completely.

This policy will also delay restarts by 500ms per successive failure.

type Service

type Service struct {
	Background                func(context.Context) context.Context
	Command                   string
	Args                      []string
	ShutdownSignal            syscall.Signal
	Env                       []string
	WorkDir                   string
	WatchedPaths              []string
	WatchedPathChangeDebounce time.Duration
	Stdin                     io.Reader
	Stdout                    io.Writer
	Stderr                    io.Writer
	RestartPolicy             RestartPolicy
	OnStart                   []func(context.Context)
	OnRestart                 []func(context.Context)
	OnExit                    []func(context.Context)
	SubprocessProvider        SubprocessProvider // used for testing
	FileEventProvider         FileEventProvider  // used for testing
	// contains filtered or unexported fields
}

Service is a specific program to start.

func (*Service) Restart

func (s *Service) Restart() (err error)

Restart tells the service to quit with the shutdown signal restarting the serivce.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start starts the service.

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the service.

type ServiceHistory

type ServiceHistory struct {
	StartedAt time.Time
	Exits     []Exit
}

ServiceHistory is the relevant bits of a service's history.

func (ServiceHistory) RecentFailures

func (sh ServiceHistory) RecentFailures() (failures []Exit)

RecentFailures returns just the last N exits that have an error.

type Subprocess

type Subprocess interface {
	Start() error
	Pid() int
	Signal(syscall.Signal) error
	Wait() error
}

Subprocess is a forked process.

type SubprocessProvider

type SubprocessProvider interface {
	Exec(context.Context, *Service) (Subprocess, error)
}

type Supervisor

type Supervisor struct {
	Services []*Service
	// contains filtered or unexported fields
}

Supervisor is a collection of services that should be started / restarted.

func (*Supervisor) Restart

func (s *Supervisor) Restart(_ context.Context) (err error)

Restart restarts all the services.

If there are errors on restart those errors are returned but no recovery or coordinated shutdown attempt is made.

func (*Supervisor) Start

func (s *Supervisor) Start(ctx context.Context) error

Start starts the services and blocks.

func (*Supervisor) StartAsync

func (s *Supervisor) StartAsync(ctx context.Context) (err error)

StartAsync starts the supervisor and does not block.

func (*Supervisor) Stop

func (s *Supervisor) Stop(_ context.Context) (err error)

Stop stops the supervisor, implementing graceful.

func (*Supervisor) Wait

func (s *Supervisor) Wait(ctx context.Context) error

Wait blocks until the services exit.

Jump to

Keyboard shortcuts

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