Documentation
¶
Index ¶
- Variables
- type Service
- type ServiceToken
- type Spec
- type Supervisor
- func (s *Supervisor) Add(service Service) ServiceToken
- func (s *Supervisor) Remove(id ServiceToken) error
- func (s *Supervisor) Serve()
- func (s *Supervisor) ServeBackground(context string)
- func (s *Supervisor) Services() []Service
- func (s *Supervisor) Stop(context string)
- func (s *Supervisor) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrWrongSupervisor = errors.New("wrong supervisor for this service token, no service removed")
ErrWrongSupervisor is returned by the (*Supervisor).Remove method if you pass a ServiceToken from the wrong Supervisor.
Functions ¶
This section is empty.
Types ¶
type Service ¶
Service interface defines the signature for services to be monitored by supervisor routine
type ServiceToken ¶
type ServiceToken struct {
// contains filtered or unexported fields
}
ServiceToken is an opaque identifier that can be used to terminate a service that has been Add()ed to a Supervisor.
type Spec ¶
type Spec struct { Log func(string) FailureDecay float64 FailureThreshold float64 FailureBackoff time.Duration Timeout time.Duration }
Spec for supervisor that's respected for re-spawning supervised routines that have crashed
type Supervisor ¶
Supervisor contruct
func New ¶
func New(name string, spec Spec) (s *Supervisor)
New is the full constructor function for a supervisor.
The supervisor tracks the number of failures that have occurred, with an exponential decay on the count. Every FailureDecay seconds, the number of failures that have occurred is cut in half. (This is done smoothly with an exponential function.) When a failure occurs, the number of failures is incremented by one. When the number of failures passes the FailureThreshold, the entire service waits for FailureBackoff seconds before attempting any further restarts, at which point it resets its failure count to zero.
Timeout is how long Suptree will wait for a service to properly terminate.
func NewSimple ¶
func NewSimple(name string) *Supervisor
NewSimple creates a service with sensible defaults.
func (*Supervisor) Add ¶
func (s *Supervisor) Add(service Service) ServiceToken
Add adds a service to this supervisor.
func (*Supervisor) Remove ¶
func (s *Supervisor) Remove(id ServiceToken) error
Remove will remove the given service from the Supervisor, and attempt to Stop() it. The ServiceID token comes from the Add() call.
func (*Supervisor) Serve ¶
func (s *Supervisor) Serve()
Serve starts the supervisor. You should call this on the top-level supervisor, but nothing else.
func (*Supervisor) ServeBackground ¶
func (s *Supervisor) ServeBackground(context string)
ServeBackground starts running a supervisor in its own goroutine. This method does not return until it is safe to use .Add() on the Supervisor.
func (*Supervisor) Services ¶
func (s *Supervisor) Services() []Service
Services returns a []Service containing a snapshot of the services this Supervisor is managing.
func (*Supervisor) Stop ¶
func (s *Supervisor) Stop(context string)
Stop stops the Supervisor.
This function will not return until either all Services have stopped, or they timeout after the timeout value given to the Supervisor at creation.
func (*Supervisor) String ¶
func (s *Supervisor) String() string
String implements the fmt.Stringer interface.