schedule

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	Cron() (*configv1alpha1.CronExecutionConfig, error)
}

Config knows how to return the cron config.

type Option

type Option func(*Schedule)

Option is a kind of functional option.

func WithClock

func WithClock(clock clock.Clock) Option

WithClock sets the clock to a custom one.

func WithConfigLoader

func WithConfigLoader(loader Config) Option

WithConfigLoader sets the config loader to a custom one.

type Schedule

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

Schedule stores a list of JobConfigs that should be scheduled, and returns any JobConfigs that are not yet scheduled.

This data structure assumes that time never goes backwards (i.e. is monotonically increasing) between successive calls. In case of clock skew which moves the clock backwards, any already scheduled jobs will be simply skipped. This data structure is not thread-safe, nor does it provide any sort of concurrency control.

func New

func New(jobConfigs []*execution.JobConfig, options ...Option) (*Schedule, error)

New returns a new Schedule initialized from a list of JobConfigs.

func (*Schedule) Bump

func (s *Schedule) Bump(jobConfig *execution.JobConfig, fromTime time.Time) (time.Time, error)

Bump will set the JobConfig's next scheduled time in the internal heap, relative to but after popTime. If the JobConfig is in the heap previously, it will be updated.

A typical pattern would involve:

  1. Call Pop() to get the next JobConfig to be scheduled. This causes it to be removed from the heap.
  2. Actually schedule the JobConfig.
  3. Call Bump() to "commit" the update, which will add it back to the internal heap with a new priority.

Ideally, the caller should only call Bump after the JobConfig has been removed (via Pop or Delete) from the heap.

func (*Schedule) Delete

func (s *Schedule) Delete(jobConfig *execution.JobConfig) error

Delete will remove the JobConfig from the internal heap. If the JobConfig did not exist, this is a no-op.

func (*Schedule) Pop

func (s *Schedule) Pop(fromTime time.Time) (string, time.Time, bool)

Pop returns the namespaced name and time of the next item to be scheduled that is not after popTime. The returned JobConfig, if any, will be removed from the heap.

Jump to

Keyboard shortcuts

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