schedule

package
v3.0.0-rc49 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OnKinds are the event kinds an action can run on: the events of the
	// node a file installed from what the node knows is to be installed
	// again on, and the install of files of the object, which what reads
	// them is to read again.
	OnKinds = []string{
		"FileInstalled",
		"NetworkPeersUpdated",
	}

	// DefaultPace is the pace of the runs of an action whose
	// pace is not set.
	DefaultPace = "@10s"
)

Functions

func InitData

func InitData()

InitData reset package objects data, it can be used for tests.

Types

type Config

type Config struct {
	Action             string `json:"action"`
	Schedule           string `json:"schedule"`
	Key                string `json:"key"`
	MaxParallel        int    `json:"max_parallel"`
	Require            string `json:"require,omitempty"`
	RequireCollector   bool   `json:"require_collector"`
	RequireProvisioned bool   `json:"require_provisioned"`
	RunDir             string `json:"-"`

	// RequireReplicationSource schedules the action on the node the
	// data is replicated from only.
	RequireReplicationSource bool `json:"require_replication_source,omitempty"`

	// StatefileKey is used in the last run filename and last run success formatters.
	// Defaults to Action if empty.
	StatefileKey string `json:"-"`

	// On are the events running the action, each one an event kind
	// and the values of the fields of the event it requires:
	// "NetworkPeersUpdated,name=backend1".
	On []string `json:"on,omitempty"`

	// Pace paces the runs the events ask for: "@30s" runs at
	// most once each 30s, "@30s backoff @1m" stretches the interval
	// up to 1m while the events keep coming.
	Pace string `json:"pace,omitempty"`
}

func (Config) Equal

func (c Config) Equal(other Config) bool

Equal says if c and other are the same schedule configuration.

type Data

type Data[T Dataer] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Data defines a shared holder for all objects Dataer

var (

	// TableData is the package data holder for all objects schedule
	TableData *Data[Table]
)

func NewData

func NewData[T Dataer]() *Data[T]

func (*Data[T]) GetAll

func (c *Data[T]) GetAll() []DataElement[T]

func (*Data[T]) GetByPath

func (c *Data[T]) GetByPath(p naming.Path) *T

func (*Data[T]) GetPaths

func (c *Data[T]) GetPaths() naming.Paths

func (*Data[T]) Set

func (c *Data[T]) Set(p naming.Path, v *T)

func (*Data[T]) Unset

func (c *Data[T]) Unset(p naming.Path)

type DataElement

type DataElement[T Dataer] struct {
	Path  naming.Path
	Value *T
}

type Dataer

type Dataer interface {
	Table
}

type Entry

type Entry struct {
	Config
	LastRunAt time.Time   `json:"last_run_at"`
	NextRunAt time.Time   `json:"next_run_at"`
	Node      string      `json:"node"`
	Path      naming.Path `json:"path"`
}

func (*Entry) GetLastRun

func (t *Entry) GetLastRun() time.Time

func (Entry) GetNext

func (t Entry) GetNext() (time.Time, time.Duration, error)

func (Entry) GetNextAt

func (t Entry) GetNextAt(tm time.Time) (time.Time, time.Duration, error)

GetNextAt returns the next time the entry is allowed to run after tm, given its last run, and the duration it stays allowed.

A caller computing a delay from a time it read passes that time, so the delay and the next date are computed from the same clock reading.

func (*Entry) LastRunFile

func (t *Entry) LastRunFile() string

func (*Entry) LastSuccessFile

func (t *Entry) LastSuccessFile() string

func (*Entry) LoadLast

func (t *Entry) LoadLast() time.Time

func (Entry) LogPrefix

func (t Entry) LogPrefix() string

func (*Entry) RID

func (t *Entry) RID() string

func (*Entry) SetLastRun

func (t *Entry) SetLastRun(tm time.Time) error

func (*Entry) SetLastSuccess

func (t *Entry) SetLastSuccess(tm time.Time) error

type OnFilter

type OnFilter struct {
	Kind   string
	Fields map[string]string
}

OnFilter is an event an action runs on: its kind, and the values of the fields of the event it requires.

func ParseOn

func ParseOn(s string) (OnFilter, error)

ParseOn returns the filter of the event s says, "<kind>[,<field>=<value>...]".

func (OnFilter) Match

func (t OnFilter) Match(key string) bool

Match says if the event whose key is key, "<kind>[,<field>=<value>...]", is the one the filter says.

type OnPace

type OnPace struct {
	Interval time.Duration
	Max      time.Duration
}

OnPace paces the runs the events ask for: a run at most each Interval, stretched up to Max while the events keep coming.

func ParsePace

func ParsePace(s string) (OnPace, error)

ParsePace returns the pace s says, "@<interval>[ backoff @<max>]", the durations written as the interval of a schedule.

type Table

type Table []Entry

func NewTable

func NewTable(entries ...Entry) Table

func (Table) Add

func (t Table) Add(i interface{}) Table

func (Table) AddEntries

func (t Table) AddEntries(l ...Entry) Table

func (Table) AddTable

func (t Table) AddTable(l Table) Table

func (Table) DeepCopy

func (t Table) DeepCopy() *Table

func (Table) DelEntry

func (t Table) DelEntry(e Entry) Table

func (Table) Merge

func (t Table) Merge(i interface{}) Table

func (Table) MergeEntries

func (t Table) MergeEntries(l ...Entry) Table

func (Table) MergeEntry

func (t Table) MergeEntry(e Entry) Table

Jump to

Keyboard shortcuts

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