scheduler

package
v0.0.0-...-dec25df Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package scheduler contains all the logic for periodic execution of tables, including construction of a dependency graph, prioritization, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Months   Months   `json:"months"`
	Weekdays Weekdays `json:"weekdays"`
	Days     Days     `json:"days"`
	Hours    Hours    `json:"hours"`
}

A Condition is a list of various time attributes such as months, weekdays, days or month, etc. This can be expanded in the future.

func (*Condition) MarshalJSON

func (c *Condition) MarshalJSON() ([]byte, error)

func (*Condition) Satisfied

func (c *Condition) Satisfied(now time.Time) bool

For each of the time attributes specified in the condition, at least one must match the passed-in time value. E.g. given an argument which is Monday, 9am Condition [Monday,Tuesday], [9am, 10am] : satisfied Condition [Tuesday,Wednesday], [9am] : not satisfied

func (*Condition) UnmarshalJSON

func (c *Condition) UnmarshalJSON(data []byte) error

type Days

type Days map[int]bool

type Graph

type Graph map[string]*node

A graph. Implemented as a map of nodes, keyed by string representing the name of this node. A node maintains maps of its parents and children, as well as has an integer Score which represents the "importance" of this node based on how many dependents it has.

func NewGraph

func NewGraph() Graph

func (Graph) ReadyItems

func (g Graph) ReadyItems() (result []Item, err error)

Return a slice of items which have no parents, meaning these items are not waiting on the parents to finish executing and are ready to run.

func (Graph) Relate

func (g Graph) Relate(parent, child Item)

Add a parent-child pair to the graph. A nil parent means this child has no parent.

func (Graph) RemoveItem

func (g Graph) RemoveItem(name string) error

Remove a node given its name.

func (Graph) Scores

func (g Graph) Scores() []scoreName

Traverse (breadth-first) the entire graph bottom up, stopping at every node to traverse (breadth-first) from that node down to count its progeny. The count is then the score. Scores array is ordered by score.

type Hours

type Hours map[int]bool

type Item

type Item interface {
	GetName() string
}

type Months

type Months map[time.Month]bool

type Run

type Run struct {
	Now time.Time
}

A Run is a collection of tasks which is to be selectively executed. The run has a notion of "now" which is when it presumably is started.

func (*Run) SelectTasks

func (r *Run) SelectTasks(tasks []Schedulable) []Schedulable

Given a list of tasks, return those whose Condition is satisfied by this Run's "Now".

type Schedulable

type Schedulable interface {
	Conditions() []*Condition
}

Schedulable describes something that can return a list of Conditions.

type Weekdays

type Weekdays map[time.Weekday]bool

Jump to

Keyboard shortcuts

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