window

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package window provides window configuration retrieval and formatting capability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigReader

type ConfigReader interface {
	PathExists(string) (bool, error)
	AbsPath(string) (string, error)
	JSONFiles(string) ([]os.FileInfo, error)
	JSONContent(string) ([]byte, error)
}

ConfigReader defines filesystem interactions for Window configurations.

type Format

type Format int16

Format defines enum type for schedule formats.

const (
	// FormatCron denotes integer value for a crontab schedule expression.
	FormatCron Format = iota + 1
)

type Map

type Map map[string][]Window

Map correlates windows to their defined labels.

func Windows

func Windows(dir string, cr ConfigReader) (Map, error)

Windows gets all defined windows within given directory.

func (Map) Add

func (m Map) Add(windows ...Window)

Add adds windows to the appropriate label element(s).

func (Map) AggregateSchedules

func (m Map) AggregateSchedules(request string) []Schedule

AggregateSchedules combines the schedules of labels that match a given string with those that overlap.

This has the potential to return two or more schedules that that do not overlap. Schedule state happens within Aukera's schedule package.

func (Map) Find

func (m Map) Find(l string) []Window

Find returns a Window slice that have the passed label.

func (Map) FindWindow

func (m Map) FindWindow(window, label string) Window

FindWindow returns a Window with a given name from a slice of windows organized by label.

func (Map) Keys

func (m Map) Keys() []string

Keys returns all configured label names.

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

MarshalJSON marshals Window Map to configuration JSON.

func (Map) UniqueWindows

func (m Map) UniqueWindows() []Window

UniqueWindows returns all distinct windows stored in the Map.

func (Map) UnmarshalJSON

func (m Map) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom window Map unmarshaler.

type Reader

type Reader struct{}

Reader is the implementation of ConfigReader for the window package.

func (Reader) AbsPath

func (r Reader) AbsPath(path string) (string, error)

AbsPath converts a given path to an absolute path and evaluates its existence.

func (Reader) JSONContent

func (r Reader) JSONContent(path string) ([]byte, error)

JSONContent returns the contents of JSON files.

func (Reader) JSONFiles

func (r Reader) JSONFiles(path string) ([]os.FileInfo, error)

JSONFiles returns all JSON files in a given directory.

func (Reader) PathExists

func (r Reader) PathExists(path string) (bool, error)

PathExists wraps auklib.PathExists for testing purposes specific to the window.Windows function.

auklib.PathExists is used in other packages in Aukera that do not have need for a ConfigReader.

type Schedule

type Schedule struct {
	Name, State   string
	Duration      time.Duration
	Opens, Closes time.Time
}

Schedule defines struct for schedule information.

func (*Schedule) Combine

func (s *Schedule) Combine(c Schedule) error

Combine combines one schedule's timeframe with another.

func (*Schedule) IsOpen

func (s *Schedule) IsOpen() bool

IsOpen determines if schedule is open based on open/close times.

func (*Schedule) MarshalJSON

func (s *Schedule) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaler for Schedule to ensure the Duration value is marshalled as a human-readable string.

func (*Schedule) Overlaps

func (s *Schedule) Overlaps(c Schedule) bool

Overlaps evalutes if one schedule falls during another.

func (Schedule) String

func (s Schedule) String() string

func (*Schedule) UnmarshalJSON

func (s *Schedule) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom unmarshaller for Schedule struct. Used with client package to retrieve window schedule.

type Window

type Window struct {
	Name, CronString string
	Format           Format
	Cron             cron.Schedule
	Duration         time.Duration
	Starts, Expires  time.Time
	Labels           []string
	Schedule         Schedule
}

Window for holding raw window JSON data.

func (*Window) Expired

func (w *Window) Expired() bool

Expired determines window validity comparing Expiration time to time.Now().

func (*Window) LastActivation

func (w *Window) LastActivation(date time.Time) time.Time

LastActivation determines the last activation time of cron.Schedule. Cron itself is unaware of the duration of the window and states the window is closed if the defined cron is in the past. LastActivation travels back in time equal to the duration between now and the "Next" activation to find the starting timestamp of the last window.

func (Window) MarshalJSON

func (w Window) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaler for Window to ensure JSON output matches the fields within its configuration file.

func (*Window) NextActivation

func (w *Window) NextActivation(ts time.Time) time.Time

NextActivation determines the next activation time of cron.Schedule. This function crawls back in time search last and current time values for match, solving case where each second within the cron string itself is a valid "Next" value.

func (*Window) Started

func (w *Window) Started() bool

Started determines window validity comparing Started time to time.Now().

func (*Window) UnmarshalJSON

func (w *Window) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom Window unmarshaler.

Jump to

Keyboard shortcuts

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