container

package module
v0.0.0-...-88ac095 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: MIT Imports: 6 Imported by: 0

README

Monitoring micro-library

GOlang library for control some long-running go-rouintings

http://godoc.org/github.com/reddec/container

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wait

func Wait(events WatchEvents) error

Wait for finish

Types

type Factory

type Factory func() (Runnable, error)

Factory that creates runnable

func RepeatFunc

func RepeatFunc(label string, fn func(ctx context.Context) error) Factory

Create factory that repeats closure

type ID

type ID string

ID of runnable

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

func (*MonitorEventEmitter) Stopped

func (bus *MonitorEventEmitter) Stopped(runnable Runnable, id ID, err error)

Stopped 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 MonitorSpawnedHandlerFunc

type MonitorSpawnedHandlerFunc func(runnable Runnable, id ID) // Listener handler function for event 'Spawned'

type MonitorStoppedHandlerFunc

type MonitorStoppedHandlerFunc func(runnable Runnable, id ID, err error) // Listener handler function for event 'Stopped'

type Runnable

type Runnable interface {
	Label() string
	Run(ctx context.Context) error
}

Base instance that can be run.

type RunnableInfo

type RunnableInfo struct {
	Instance Runnable
	ID       ID
}

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 WatchEventStarted

type WatchEventStarted RunnableInfo

Event when runnable started

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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