Documentation
¶
Index ¶
- func Wait(events WatchEvents) error
- type Factory
- type ID
- type Monitor
- type MonitorEventEmitter
- func (bus *MonitorEventEmitter) AddHandler(handler Monitor)
- func (bus *MonitorEventEmitter) NoSpawned(handler MonitorSpawnedHandlerFunc)
- func (bus *MonitorEventEmitter) NoStopped(handler MonitorStoppedHandlerFunc)
- func (bus *MonitorEventEmitter) OnSpawned(handler MonitorSpawnedHandlerFunc)
- func (bus *MonitorEventEmitter) OnStopped(handler MonitorStoppedHandlerFunc)
- func (bus *MonitorEventEmitter) RemoveHandler(handler Monitor)
- func (bus *MonitorEventEmitter) Spawned(runnable Runnable, id ID)
- func (bus *MonitorEventEmitter) Stopped(runnable Runnable, id ID, err error)
- type MonitorEvents
- type MonitorSpawnedHandlerFunc
- type MonitorStoppedHandlerFunc
- type Runnable
- type RunnableInfo
- type Supervisor
- type WatchEventStarted
- type WatchEventStopped
- type WatchEvents
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Monitor ¶
type Monitor interface {
Spawned(runnable Runnable, id ID)
Stopped(runnable Runnable, id ID, err error)
}
Monitor events of state in supervisor
type MonitorEventEmitter ¶
type MonitorEventEmitter struct {
MonitorEvents // Implements listener operations
// contains filtered or unexported fields
}
MonitorEventEmitter implements events listener and events emitter operations for events Spawned, Stopped
func (*MonitorEventEmitter) AddHandler ¶
func (bus *MonitorEventEmitter) AddHandler(handler Monitor)
AddHandler adds handler for events (Spawned, Stopped)
func (*MonitorEventEmitter) NoSpawned ¶
func (bus *MonitorEventEmitter) NoSpawned(handler MonitorSpawnedHandlerFunc)
NoSpawned excludes event listener
func (*MonitorEventEmitter) NoStopped ¶
func (bus *MonitorEventEmitter) NoStopped(handler MonitorStoppedHandlerFunc)
NoStopped excludes event listener
func (*MonitorEventEmitter) OnSpawned ¶
func (bus *MonitorEventEmitter) OnSpawned(handler MonitorSpawnedHandlerFunc)
OnSpawned adds event listener for event 'Spawned'
func (*MonitorEventEmitter) OnStopped ¶
func (bus *MonitorEventEmitter) OnStopped(handler MonitorStoppedHandlerFunc)
OnStopped adds event listener for event 'Stopped'
func (*MonitorEventEmitter) RemoveHandler ¶
func (bus *MonitorEventEmitter) RemoveHandler(handler Monitor)
RemoveHandler remove handler for events
func (*MonitorEventEmitter) Spawned ¶
func (bus *MonitorEventEmitter) Spawned(runnable Runnable, id ID)
Spawned emits event with same name
type MonitorEvents ¶
type MonitorEvents interface {
// Spawned adds event listener for event 'Spawned'
OnSpawned(handler MonitorSpawnedHandlerFunc)
// NoSpawned excludes event listener
NoSpawned(handler MonitorSpawnedHandlerFunc)
// Stopped adds event listener for event 'Stopped'
OnStopped(handler MonitorStoppedHandlerFunc)
// NoStopped excludes event listener
NoStopped(handler MonitorStoppedHandlerFunc)
// AddHandler adds handler for events (Spawned, Stopped)
AddHandler(handler Monitor)
// RemoveHandler remove handler for events
RemoveHandler(handler Monitor)
}
MonitorEvents is a client side of event bus that allows subscribe to Spawned, Stopped events
type RunnableInfo ¶
General information about runnable
type Supervisor ¶
type Supervisor interface {
// Watch runnable and restart if needed but not more then restartLimit. If restartLimit is negative, it's mean infinity.
// If runnable stopped with error and stopOnError is true, then watch loop exits.
// Events MUST be consumed
Watch(ctx context.Context, factory Factory, restartLimit int, restartDelay time.Duration, stopOnError bool) WatchEvents
// Spawn and monitor one runnable in background. Returns generated ID, done channel (buffered) and stop function
Spawn(runnable Runnable) (ID, <-chan error, func())
// SpawnFunc creates and spawn ClosureWrapper runnable
SpawnFunc(label string, closure func(ctx context.Context) error) (ID, <-chan error, func())
// List all runnables
List() []RunnableInfo
// Get runnable by generated ID
Get(ID) Runnable
// Events emitter of runnable
Events() MonitorEvents
// Close supervisor and stops all processes
Close()
}
Supervisor monitors group of processes
func NewSupervisor ¶
func NewSupervisor(logger *log.Logger) Supervisor
type WatchEventStopped ¶
type WatchEventStopped struct {
RunnableInfo
Error error
}
Event when runnable stopped
type WatchEvents ¶
type WatchEvents <-chan interface{}
Stream of events (WatchEventStarted or WatchEventStopped) while process running