options

package
v1.7.0-rc7 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package options provides ways to extract the task-related options from a Flux script.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateIntervalField     = errors.New("cannot use both cron and every in task options")
	ErrNoTaskOptionsDefined       = errors.New("no task options defined")
	ErrMultipleTaskOptionsDefined = errors.New("multiple task options defined")
	ErrNoASTFile                  = errors.New("expected parsed file, but found none")
)

Functions

func Parse

func Parse(source string) (*ast.Package, error)

parse will take flux source code and produce a package. If there are errors when parsing, the first error is returned. An ast.Package may be returned when a parsing error occurs, but it may be null if parsing didn't even occur.

This will return an error if the FluxLanguageService is nil.

func ParseSignedDuration

func ParseSignedDuration(text string) (*ast.DurationLiteral, error)

ParseSignedDuration is a helper wrapper around parser.ParseSignedDuration. We use it because we need to clear the basenode, but flux does not.

Types

type Duration

type Duration struct {
	Node ast.DurationLiteral
}

Duration is a time span that supports the same units as the flux parser's time duration, as well as negative length time spans.

func MustParseDuration

func MustParseDuration(s string) (dur *Duration)

MustParseDuration parses a string and returns a duration. It panics if there is an error.

func (*Duration) Add

func (a *Duration) Add(t time.Time) (time.Time, error)

Add adds the duration to a time.

func (*Duration) DurationFrom

func (a *Duration) DurationFrom(t time.Time) (time.Duration, error)

DurationFrom gives us a time.Duration from a time. Currently because of how flux works, this is just an approfimation for any time unit larger than hours.

func (*Duration) IsZero

func (a *Duration) IsZero() bool

IsZero checks if each segment of the duration is zero, it doesn't check if the Duration sums to zero, just if each internal duration is zero.

func (Duration) MarshalText

func (a Duration) MarshalText() ([]byte, error)

MarshalText marshals text into a Duration.

func (*Duration) Parse

func (a *Duration) Parse(s string) error

Parse parses a string into a Duration.

func (Duration) String

func (a Duration) String() string

func (*Duration) UnmarshalText

func (a *Duration) UnmarshalText(text []byte) error

UnmarshalText unmarshals text into a Duration.

type FluxLanguageService

type FluxLanguageService interface {
	// Parse will take flux source code and produce a package.
	// If there are errors when parsing, the first error is returned.
	// An ast.Package may be returned when a parsing error occurs,
	// but it may be null if parsing didn't even occur.
	Parse(source string) (*ast.Package, error)

	// EvalAST will evaluate and run an AST.
	EvalAST(ctx context.Context, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error)
}

FluxLanguageService is a service for interacting with flux code.

type Options

type Options struct {
	// Name is a non optional name designator for each task.
	Name string `json:"name,omitempty"`

	// Cron is a cron style time schedule that can be used in place of Every.
	Cron string `json:"cron,omitempty"`

	// Every represents a fixed period to repeat execution.
	// this can be unmarshaled from json as a string i.e.: "1d" will unmarshal as 1 day
	Every Duration `json:"every,omitempty"`

	// Offset represents a delay before execution.
	// this can be unmarshaled from json as a string i.e.: "1d" will unmarshal as 1 day
	Offset *Duration `json:"offset,omitempty"`

	Concurrency *int64 `json:"concurrency,omitempty"`

	Retry *int64 `json:"retry,omitempty"`
}

Options are the task-related options that can be specified in a Flux script.

func FromScriptAST

func FromScriptAST(script string) (Options, error)

FromScriptAST extracts Task options from a Flux script using only the AST (no evaluation of the script). Using AST here allows us to avoid having to contend with functions that aren't available in some parsing contexts (within Gateway for example).

func (*Options) Clear

func (o *Options) Clear()

Clear clears out all options in the options struct, it us useful if you wish to reuse it.

func (*Options) EffectiveCronString

func (o *Options) EffectiveCronString() string

EffectiveCronString returns the effective cron string of the options. If the cron option was specified, it is returned. If the every option was specified, it is converted into a cron string using "@every". Otherwise, the empty string is returned. The value of the offset option is not considered. TODO(docmerlin): create an EffectiveCronStringFrom(t time.Time) string, that works from a unit of time. Do not use this if you haven't checked for validity already.

func (*Options) IsZero

func (o *Options) IsZero() bool

IsZero tells us if the options has been zeroed out.

func (*Options) Validate

func (o *Options) Validate() error

Validate returns an error if the options aren't valid.

Jump to

Keyboard shortcuts

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