Documentation ¶
Overview ¶
Package options provides ways to extract the task-related options from a Flux script.
Index ¶
- Variables
- func ParseSignedDuration(text string) (*ast.DurationLiteral, error)
- type Duration
- func (a *Duration) Add(t time.Time) (time.Time, error)
- func (a *Duration) DurationFrom(t time.Time) (time.Duration, error)
- func (a *Duration) IsZero() bool
- func (a Duration) MarshalText() ([]byte, error)
- func (a *Duration) Parse(s string) error
- func (a Duration) String() string
- func (a *Duration) UnmarshalText(text []byte) error
- type FluxLanguageService
- type Options
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
MustParseDuration parses a string and returns a duration. It panics if there is an error.
func (*Duration) DurationFrom ¶
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 ¶
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 ¶
MarshalText marshals text into a Duration.
func (*Duration) UnmarshalText ¶
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(lang FluxLanguageService, 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 ¶
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.