Documentation
¶
Index ¶
- func NoopFunc(_ctx context.Context) error
- type ConfigurationStatus
- type Controller
- type Func
- type FuncParam
- type Function
- type Internal
- type Manager
- func (m *Manager) GetAllControllers() []string
- func (m *Manager) GetStats() []*Status
- func (m *Manager) Lookup(name string) *Controller
- func (m *Manager) RemoveAll()
- func (m *Manager) RemoveAllAndWait()
- func (m *Manager) RemoveController(name string) error
- func (m *Manager) RemoveControllerAndWait(name string) error
- func (m *Manager) Terminate()
- func (m *Manager) UpdateController(name, cType string, internal Internal) error
- func (m *Manager) Wait()
- type Map
- type RunStatus
- type Scheduler
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConfigurationStatus ¶
ConfigurationStatus represents the configuration of controller.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is the actual underlying controller. Each controller is created for a specific task which is specified in `controller.internal`
func (*Controller) RunController ¶
func (c *Controller) RunController()
RunController starts running the controller. TODO: improve this, currently it waits for the current request to finish and then waits for interval duration to run the function again. This is not a constant interval check we are looking for, so wrap the runFunc inside a goroutine.
func (*Controller) Status ¶
func (c *Controller) Status() *Status
Status returns the current status of the controller.
type Func ¶
Func represents an underlying function executed by the controller. A controller function is uniquely identified by its name.
func NewControllerFunction ¶
NewControllerFunction returns an instance of a new controller function.
type FuncParam ¶
type FuncParam interface{}
FuncParam is an interface staisfied by all the function parameter types.
type Internal ¶
type Internal struct {
// DoFunc is the function that will be run until it succeeds and/or
// using the interval RunInterval if not 0.
// An unset DoFunc is an error and will be logged as one.
DoFunc *Func
// StopFunc is called when the controller stops. It is intended to run any
// clean-up tasks for the controller (e.g. deallocate/release resources)
// It is guaranteed that DoFunc is called at least once before StopFunc is
// called.
// An unset StopFunc is not an error (and will be a no-op)
// Note: Since this occurs on controller exit, error counts and tracking may
// not be checked after StopFunc is run.
StopFunc *Func
// If set to any other value than 0, will cause DoFunc to be run in the
// specified interval. The interval starts from when the DoFunc has
// returned last
RunInterval time.Duration
// ErrorRetryBaseDuration is the initial time to wait to run DoFunc
// again on return of an error. On each consecutive error, this value
// is multiplied by the number of consecutive errors to provide a
// constant back off. The default is 1s.
ErrorRetryBaseDuration time.Duration
// Should we have a constant back off for retries during errors.
RetryBackOff bool
// NoErrorRetry when set to true, disables retries on errors
NoErrorRetry bool
// SkipFirstRun skips the first run of the controller function.
SkipFirstRun bool
// contains filtered or unexported fields
}
Internal contains all parameters of a controller, including the functions to run and other metadata related to runs.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages a ControllerMap and perform actions on it.
func NewManager ¶
func NewManager() *Manager
NewManager Creates a new manager instance for the controller map.
func (*Manager) GetAllControllers ¶
GetAllControllers Returns the name of all the controllers that are managed by this manager.
func (*Manager) Lookup ¶
func (m *Manager) Lookup(name string) *Controller
Lookup looks up for the controller with the provided name.
func (*Manager) RemoveAll ¶
func (m *Manager) RemoveAll()
RemoveAll stops and removes all controllers of the manager
func (*Manager) RemoveAllAndWait ¶
func (m *Manager) RemoveAllAndWait()
RemoveAllAndWait stops and removes all controllers of the manager and then waits for all controllers to exit
func (*Manager) RemoveController ¶
RemoveController stops and removes a controller from the manager. If DoFunc is currently running, DoFunc is allowed to complete in the background.
func (*Manager) RemoveControllerAndWait ¶
RemoveControllerAndWait stops and removes a controller using RemoveController() and then waits for it to run to completion.
func (*Manager) Terminate ¶
func (m *Manager) Terminate()
Terminate terminates all the controllers managed by the manager.
func (*Manager) UpdateController ¶
UpdateController installs or updates a controller in the manager. A controller is identified by its name. If a controller with the name already exists, the controller will be shut down and replaced with the provided controller. Updating a controller will cause the DoFunc to be run immediately regardless of any previous conditions. It will also cause any statistics to be reset.
type Map ¶
type Map map[string]*Controller
Map is the map of a controller name with the underlying Controller.
type RunStatus ¶
type RunStatus struct {
SuccessCount int64
LastSuccessStamp string
FailureCount int64
LastFailureStamp string
ConsecutiveFailureCount int64
}
RunStatus represents the status of a running controller.
type Scheduler ¶
type Scheduler interface {
// Next returns the time when to run the controller function again.
Next(time.Time) time.Time
}
Scheduler is the interface for custom scheduler implementation of controller function.
type Status ¶
type Status struct {
Name string
Configuration ConfigurationStatus
Status RunStatus
}
Status represents status of controller.