sched

package
v0.0.0-...-d304e97 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DailyType    = "daily"
	MonthlyType  = "monthly"
	WeeklyType   = "weekly"
	PeriodicType = "periodic"

	MonthlyRetain = 12
	WeeklyRetain  = 5
	DailyRetain   = 7
)
View Source
const (
	TaskNone = TaskID(0)
)

Variables

View Source
var ParseCLI = map[string]func(string) (RetainIntervalSpec, error){
	DailyType:   parseDaily,
	WeeklyType:  parseWeekly,
	MonthlyType: parseMonthly,
}

Functions

func Init

func Init(minimumInterval time.Duration)

func IntervalType

func IntervalType(interval Interval) string

func IsIntervalType

func IsIntervalType(t string) bool

func ParseScheduleAndPolicies

func ParseScheduleAndPolicies(scheduleString string) (
	[]RetainInterval,
	*PolicyTags,
	error,
)

func SamePolicyTags

func SamePolicyTags(p1, p2 *PolicyTags) bool

func ScheduleIntervalSummary

func ScheduleIntervalSummary(items []Interval, policyTags *PolicyTags) string

func ScheduleString

func ScheduleString(items []RetainIntervalSpec, p *PolicyTags) (string, error)

func ScheduleStringRetainInv

func ScheduleStringRetainInv(
	intvs []RetainInterval,
	p *PolicyTags,
) (string, error)

func ScheduleSummary

func ScheduleSummary(items []RetainInterval, policyTags *PolicyTags) string

func SpeedUp

func SpeedUp()

SpeedUp advances teh clock faster for tests.

func ValidTaskID

func ValidTaskID(t TaskID) bool

Types

type Interval

type Interval interface {
	String() string
	IntervalType() string
	Spec() IntervalSpec
	// contains filtered or unexported methods
}

func Daily

func Daily(hour int, minute int) Interval

func Monthly

func Monthly(day int, hour int, minute int) Interval

func Periodic

func Periodic(period time.Duration) Interval

func Weekly

func Weekly(dow time.Weekday, hour int, minute int) Interval

type IntervalSpec

type IntervalSpec struct {
	Freq    string
	Period  uint64 `yaml:"period,omitempty"`
	Month   int    `yaml:"month,omitempty"`
	Weekday int    `yaml:"weekday,omitempty"`
	Day     int    `yaml:"day,omitempty"`
	Hour    int    `yaml:"hour,omitempty"`
	Minute  int    `yaml:"minute,omitempty"`
}

type PolicyTags

type PolicyTags struct {
	// Names is the list of policy names
	Names []string
}

PolicyTags groups one or more policies together.

func NewPolicyTags

func NewPolicyTags(policies string) (*PolicyTags, error)

func NewPolicyTagsFromSlice

func NewPolicyTagsFromSlice(policies []string) (*PolicyTags, error)

NewPolicyTagsFromSlice returns a new object from a string slice of names

func ParsePolicyTags

func ParsePolicyTags(policyTagsStr string) (*PolicyTags, error)

func (*PolicyTags) String

func (p *PolicyTags) String() string

func (*PolicyTags) Summary

func (p *PolicyTags) Summary() string

type RetainInterval

type RetainInterval interface {
	Interval
	// RetainNumber is the number of instances to retain
	RetainNumber() uint32
	// RetainIntervalSpec returns RetainIntervalSpec
	RetainIntervalSpec() RetainIntervalSpec
}

RetainInterval is a schedule interval with a number of instances to retain.

func NewRetainInterval

func NewRetainInterval(iv Interval) RetainInterval

func ParseSchedule

func ParseSchedule(schedule string) ([]RetainInterval, error)

func SetupIntvWithDefaults

func SetupIntvWithDefaults(intvs []RetainInterval) []RetainInterval

type RetainIntervalImpl

type RetainIntervalImpl struct {
	// contains filtered or unexported fields
}

RetainIntervalImpl implements the RetainInterval interface

func (RetainIntervalImpl) IntervalType

func (p RetainIntervalImpl) IntervalType() string

func (RetainIntervalImpl) RetainIntervalSpec

func (p RetainIntervalImpl) RetainIntervalSpec() RetainIntervalSpec

func (RetainIntervalImpl) RetainNumber

func (p RetainIntervalImpl) RetainNumber() uint32

func (RetainIntervalImpl) Spec

func (RetainIntervalImpl) String

func (p RetainIntervalImpl) String() string

type RetainIntervalSpec

type RetainIntervalSpec struct {
	IntervalSpec `yaml:",inline"`
	Retain       uint32 `yaml:"retain,omitempty"`
}

RetainIntervalSpec is the serialized form of retain interval

func ParsePeriodic

func ParsePeriodic(input string) (RetainIntervalSpec, error)

type ScheduleTask

type ScheduleTask func(Interval)

type Scheduler

type Scheduler interface {
	// Schedule given task at given interval.
	// Returns associated task id if scheduled successfully,
	// or a non-nil error in case of error.
	Schedule(task ScheduleTask, interval Interval,
		runAt time.Time, onlyOnce bool) (TaskID, error)

	// Cancel given task.
	Cancel(taskID TaskID) error

	// Restart scheduling.
	Start()

	// Stop scheduling.
	Stop()
}

func Instance

func Instance() Scheduler

func New

func New(minimumInterval time.Duration) Scheduler

type TaskID

type TaskID uint64

Jump to

Keyboard shortcuts

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