Documentation
¶
Overview ¶
Package controller implements controller and manager.
Controllers can be used to run a specific task repetitively at regular intervals of time. A controller stores the resulting stats of runs with itself until pulled from it.
A manager is used to orchestrate multiple controllers running concurrently.
Index ¶
- type Controller
- func (c *Controller) ID() string
- func (c *Controller) Interval() time.Duration
- func (c *Controller) Name() string
- func (c *Controller) PullAllStats() map[time.Time]*RunStat
- func (c *Controller) PullLatestStat() *RunStat
- func (c *Controller) Start()
- func (c *Controller) Stop()
- func (c *Controller) UpdateFunc(fn RunnerFunc) error
- func (c *Controller) UpdateInterval(interval time.Duration) error
- func (c *Controller) Wait()
- type Manager
- func (m *Manager) Close()
- func (m *Manager) ListControllers() map[string]string
- func (m *Manager) PullAllStats() map[string][]*RunStat
- func (m *Manager) PullLatestStats() map[string]*RunStat
- func (m *Manager) RemoveAll()
- func (m *Manager) RemoveAllAndWait()
- func (m *Manager) RemoveController(id string)
- func (m *Manager) RemoveControllerAndWait(id string)
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) UpdateController(opts *Opts) error
- func (m *Manager) Wait()
- type Opts
- type RunStat
- type RunnerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller runs a specific operation infinitely until the context is canceled at regular intervals of time.
func NewController ¶
func NewController(ctx context.Context, opts *Opts) (*Controller, error)
NewController creates a new controller with given name and type and runs the function at regular `interval`s of time without blocking.
func (*Controller) Interval ¶
func (c *Controller) Interval() time.Duration
Interval returns the interval after which the controller executes the function.
func (*Controller) Name ¶
func (c *Controller) Name() string
Name returns the name of the controller.
func (*Controller) PullAllStats ¶
func (c *Controller) PullAllStats() map[time.Time]*RunStat
PullAllStats fetches the stats for the controller and also cleans up the stats.
func (*Controller) PullLatestStat ¶
func (c *Controller) PullLatestStat() *RunStat
PullLatestStat fetches only the latest stat from the controller and cleans up the stats.
func (*Controller) Start ¶
func (c *Controller) Start()
Start starts the execution of the controller.
func (*Controller) Stop ¶
func (c *Controller) Stop()
Stop stops the execution of the controller. It does not wait for controller to complete. Use `Wait` for that.
func (*Controller) UpdateFunc ¶
func (c *Controller) UpdateFunc(fn RunnerFunc) error
UpdateFunc updates the controller function.
func (*Controller) UpdateInterval ¶
func (c *Controller) UpdateInterval(interval time.Duration) error
UpdateInterval updates the interval of the controller.
func (*Controller) Wait ¶
func (c *Controller) Wait()
Wait waits for execution of the controller to be complete.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple controllers and running at the same time.
func NewManager ¶
NewManager creates a new manager with no controllers.
func (*Manager) Close ¶
func (m *Manager) Close()
Close closes all the controller irrespective of whether they shutdown properly.
func (*Manager) ListControllers ¶
ListControllers lists all the controllers managed by the manager.
This returns a map of controller ID with it's name.
func (*Manager) PullAllStats ¶
PullAllStats gets all the stats for all the controllers registered with the manager.
func (*Manager) PullLatestStats ¶
PullLatestStats gets latest stat for each controller in the manager.
func (*Manager) RemoveAll ¶
func (m *Manager) RemoveAll()
RemoveAll removes all the controllers from the manager.
func (*Manager) RemoveAllAndWait ¶
func (m *Manager) RemoveAllAndWait()
RemoveAllAndWait removes all the controllers and waits for them to stop completely.
func (*Manager) RemoveController ¶
RemoveController removes the controller from manager if it exists. If it doesn't, it does nothing. It does not wait for controller to stop.
func (*Manager) RemoveControllerAndWait ¶
RemoveControllerAndWait is like RemoveController but waits for completion of controller.
func (*Manager) Shutdown ¶
Shutdown gracefully attempts to close the manager and terminate and remove all the controllers. In case of error, the manager is not closed, and hence `Close` is required to be called to terminate the manager.
func (*Manager) UpdateController ¶
UpdateController updates the controller if it exists with the same name or creates a new controller if it doesn't.
type Opts ¶
type Opts struct { ID string Name string Interval time.Duration Func RunnerFunc }
Opts are the options required to create a new controller.
type RunnerFunc ¶
RunnerFunc is the function that runs after each tick.