Documentation
¶
Overview ¶
Package options provides ways to extract the task-related options from a Flux script.
Index ¶
- Variables
- func ErrMissingRequiredTaskOption(opt string) error
- func ErrParseTaskOptionField(opt string) error
- func ErrTaskInvalidDuration(err error) error
- 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 = fmt.Errorf("cannot use both cron and every in task options")
)
Functions ¶
func ErrParseTaskOptionField ¶
func ErrTaskInvalidDuration ¶
ErrTaskInvalidDuration is returned when an "every" or "offset" option is invalid in a task.
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 FromScript ¶
func FromScript(lang FluxLanguageService, script string) (Options, error)
FromScript extracts Options from a Flux script.
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.