policy

package
v1.5.0-rc5 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlternatePolicy

type AlternatePolicy struct {
	//To sync the related operations.
	*sync.RWMutex
	// contains filtered or unexported fields
}

AlternatePolicy is a policy that repeatedly executing tasks with specified duration during a specified time scope.

func NewAlternatePolicy

func NewAlternatePolicy(name string, config *AlternatePolicyConfiguration) *AlternatePolicy

NewAlternatePolicy is constructor of creating AlternatePolicy. Accept name and configuration as parameters.

func (*AlternatePolicy) AttachTasks

func (alp *AlternatePolicy) AttachTasks(tasks ...task.Task) error

AttachTasks is an implementation of same method in policy interface.

func (*AlternatePolicy) Disable

func (alp *AlternatePolicy) Disable() error

Disable is an implementation of same method in policy interface.

func (*AlternatePolicy) Done

func (alp *AlternatePolicy) Done() <-chan bool

Done is an implementation of same method in policy interface.

func (*AlternatePolicy) Equal

func (alp *AlternatePolicy) Equal(p Policy) bool

Equal is an implementation of same method in policy interface.

func (*AlternatePolicy) Evaluate

func (alp *AlternatePolicy) Evaluate() (<-chan bool, error)

Evaluate is an implementation of same method in policy interface.

func (*AlternatePolicy) GetConfig

GetConfig returns the current configuration options of this policy.

func (*AlternatePolicy) IsEnabled

func (alp *AlternatePolicy) IsEnabled() bool

IsEnabled is an implementation of same method in policy interface.

func (*AlternatePolicy) Name

func (alp *AlternatePolicy) Name() string

Name is an implementation of same method in policy interface.

func (*AlternatePolicy) Tasks

func (alp *AlternatePolicy) Tasks() []task.Task

Tasks is an implementation of same method in policy interface.

type AlternatePolicyConfiguration

type AlternatePolicyConfiguration struct {
	//Duration is the interval of executing attached tasks.
	//E.g: 24*3600 for daily
	//     7*24*3600 for weekly
	Duration time.Duration

	//An integer to indicate the the weekday of the week. Please be noted that Sunday is 7.
	//Use default value 0 to indicate weekday is not set.
	//To support by weekly function.
	Weekday int8

	//OffsetTime is the execution time point of each turn
	//It's a number to indicate the seconds offset to the 00:00 of UTC time.
	OffsetTime int64
}

AlternatePolicyConfiguration store the related configurations for alternate policy.

type Policy

type Policy interface {
	//Name will return the name of the policy.
	//If the policy supports multiple instances, please make sure the name is unique as an UUID.
	Name() string

	//Tasks will return the attached tasks with this policy.
	Tasks() []task.Task

	//AttachTasks is to attach tasks to this policy
	AttachTasks(...task.Task) error

	//Done will setup a channel for other components to check whether or not
	//the policy is completed. Possibly designed for the none loop policy.
	Done() <-chan bool

	//Evaluate the policy based on its definition and return the result via
	//result channel. Policy is enabled after it is evaluated.
	//Make sure Evaluate is idempotent, that means one policy can be only enabled
	//only once even if Evaluate is called more than one times.
	Evaluate() (<-chan bool, error)

	//Disable the enabled policy and release all the allocated resources.
	Disable() error

	//Equal will compare the two policies based on related factors if existing such as confgiuration etc.
	//to determine whether the two policies are same ones or not. Please pay attention that, not every policy
	//needs to support this method. If no need, please directly return false to indicate each policies are
	//different.
	Equal(p Policy) bool

	//IsEnabled is to indicate whether the policy is enabled or not (disabled).
	IsEnabled() bool
}

Policy is an if-then logic to determine how the attached tasks should be executed based on the evaluation result of the defined conditions. E.g:

Daily execute TASK between 2017/06/24 and 2018/06/23
Execute TASK at 2017/09/01 14:30:00

Each policy should have a name to identify itself. Please be aware that policy with no tasks will be treated as invalid.

Jump to

Keyboard shortcuts

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