supervisor

package
v1.89.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ISupervisor

type ISupervisor interface {
	// Run will run the supervisor and execute any of the command hooks. If it receives a halting error or the context is cancelled then it will exit
	Run(ctx context.Context) error
}

ISupervisor will run a command and automatically restart it if it exits. Hooks can be used to execute code at different points in the execution lifecyle. Restarts can be delayed

type Supervisor

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

A Supervisor will run a command and automatically restart it if it exits. Hooks can be used to execute code at different points in the execution lifecyle. Restarts can be delayed

func NewSupervisor

func NewSupervisor(newCommand func(ctx context.Context) (*subprocess.Subprocess, error), opts ...SupervisorOption) *Supervisor

NewSupervisor will take a function 'newCommand' that creates a command and run it every time the command exits. Options can be supplied by the 'opts' variadic argument that control the lifecyle of the supervisor

func (*Supervisor) Run

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

Run will run the supervisor and execute any of the command hooks. If it receives a halting error or the context is cancelled then it will exit

type SupervisorOption

type SupervisorOption func(*Supervisor)

func WithHaltingErrors

func WithHaltingErrors(errs ...error) SupervisorOption

WithHaltingErrors are errors that won't trigger the supervisor to restart and on which, the subprocess will just halt.

func WithPostStart

func WithPostStart(function func(context.Context) error) SupervisorOption

WithPostStart will run 'function' after the supervisor has started

func WithPostStop

func WithPostStop(function func(context.Context, error) error) SupervisorOption

WithPostStop will run 'function' after the supervised command has stopped It's context will ignore cancellations so any timeouts should be added within the function body itself

func WithPreStart

func WithPreStart(function func(context.Context) error) SupervisorOption

WithPreStart will run 'function' before the supervisor starts

func WithRestartDelay

func WithRestartDelay(delay time.Duration) SupervisorOption

WithRestartDelay will delay the supervisor from restarting for a period of time specified by 'delay'

Jump to

Keyboard shortcuts

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