Documentation
¶
Index ¶
- Constants
- type ExecSubprocess
- type ExecSubprocessProvider
- type Exit
- type FileEventProvider
- type MockNotifyProvider
- type MockSubprocess
- type MockSubprocessProvider
- type NotifyProvider
- type PrefixWriter
- type RestartPolicy
- type Service
- type ServiceHistory
- type Subprocess
- type SubprocessProvider
- type Supervisor
Constants ¶
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`.
type ExecSubprocessProvider ¶
type ExecSubprocessProvider struct{}
ExecSubprocessProvider is the exec subprocess provider.
func (ExecSubprocessProvider) Exec ¶
func (e ExecSubprocessProvider) Exec(ctx context.Context, svc *Service) (Subprocess, error)
type FileEventProvider ¶
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 ¶
func (m MockSubprocessProvider) Exec(ctx context.Context, svc *Service) (Subprocess, error)
Exec returns a new mocked subprocess.
type PrefixWriter ¶
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 ¶
Restart tells the service to quit with the shutdown signal restarting the serivce.
type ServiceHistory ¶
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 ¶
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.