engine

package
v0.260504.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: CC0-1.0 Imports: 13 Imported by: 0

Documentation

Overview

Engine tasks: - let drivers register actions - parse scenario .dot files - execute scenarios

Index

Constants

View Source
const ContextKey = "run/engine"
View Source
const FmtErrContext = "`%s`" // errors.Annotatef(err, FmtErrContext, doer.String())

Variables

View Source
var (
	ErrArgNotApplied = errors.Errorf("Argument is not applied")
	ErrArgOverwrite  = errors.Errorf("Argument already applied")
)

Functions

func IsNotResolved

func IsNotResolved(x interface{}) bool

IsNotResolved Test `error` or `Doer` against ErrNotResolved

Types

type Arg

type Arg interface{}

type ArgApplier

type ArgApplier interface {
	Apply(a Arg) (Doer, bool, error)
}

type CalculationFunc added in v0.250114.0

type CalculationFunc func() float64

type Doer

type Doer interface {
	Validate() error
	Calculation() float64
	Do(context.Context) error
	String() string // for logs
	AddErrorAction(code string, d Doer, skipMain bool)
	FixErrorAction(code string) Doer
}

func ArgApply

func ArgApply(d Doer, arg Arg) (Doer, bool, error)

func Force

func Force(d Doer) (Doer, bool, error)

type Engine

type Engine struct {
	Log *log2.Log
	// contains filtered or unexported fields
}

func GetGlobal

func GetGlobal(ctx context.Context) *Engine

func NewEngine

func NewEngine(log *log2.Log) *Engine

func (*Engine) CheckAction added in v0.260428.0

func (e *Engine) CheckAction(action string) (ok bool, doer Doer)

func (*Engine) Exec

func (e *Engine) Exec(ctx context.Context, d Doer) error

func (*Engine) ExecList

func (e *Engine) ExecList(ctx context.Context, tag string, list []string) []error

func (*Engine) ExecPart

func (e *Engine) ExecPart(ctx context.Context, d Doer) error

func (*Engine) List

func (e *Engine) List() []string

func (*Engine) ParseText

func (e *Engine) ParseText(tag, text string) (Doer, error)

func (*Engine) Register

func (e *Engine) Register(action string, d Doer)

func (*Engine) RegisterNewFunc

func (e *Engine) RegisterNewFunc(name string, fun func(context.Context) error)

func (*Engine) RegisterNewFuncAgr added in v0.230424.2

func (e *Engine) RegisterNewFuncAgr(name string, fun func(ctx context.Context, arg Arg) error)

func (*Engine) RegisterNewSeq

func (e *Engine) RegisterNewSeq(name string, ds ...Doer)

func (*Engine) RegisterParse

func (e *Engine) RegisterParse(name, scenario string) error

func (*Engine) Resolve

func (e *Engine) Resolve(action string) Doer

func (*Engine) ResolveOrLazy

func (e *Engine) ResolveOrLazy(action string) (Doer, error)

func (*Engine) SetProfile

func (e *Engine) SetProfile(re *regexp.Regexp, min time.Duration, fun ProfileFunc)

SetProfile re=nil or fun=nil to disable profiling.

func (*Engine) TestDo

func (e *Engine) TestDo(t testing.TB, ctx context.Context, name string)

func (*Engine) ValidateExec

func (e *Engine) ValidateExec(ctx context.Context, d Doer) error

type ErrNotResolved

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

func NewErrNotResolved

func NewErrNotResolved(action string) ErrNotResolved

func (ErrNotResolved) Error

func (e ErrNotResolved) Error() string

type ErrorActionEntry added in v0.260428.0

type ErrorActionEntry struct {
	Doer     Doer
	SkipMain bool
}

type Fail

type Fail struct{ E error }

func (Fail) Calculation added in v0.250114.0

func (f Fail) Calculation() float64

func (Fail) Do

func (f Fail) Do(ctx context.Context) error

func (Fail) String

func (f Fail) String() string

func (Fail) Validate

func (f Fail) Validate() error

type Forcer

type Forcer interface{ Force() (Doer, bool, error) }

type Func

type Func struct {
	Name   string
	F      func(context.Context) error
	ErrorF map[string]func(context.Context) error
	V      ValidateFunc
	C      CalculationFunc
}

func (Func) AddErrorAction added in v0.260428.0

func (f Func) AddErrorAction(code string, d Doer, skipMain bool)

func (Func) Calculation added in v0.250114.0

func (f Func) Calculation() float64

func (Func) Do

func (f Func) Do(ctx context.Context) error

func (Func) FixErrorAction added in v0.260428.0

func (f Func) FixErrorAction(code string) Doer

func (Func) String

func (f Func) String() string

func (Func) Validate

func (f Func) Validate() error

type Func0

type Func0 struct {
	Name   string
	F      func() error
	ErrorF map[int32]func(context.Context) error
	V      ValidateFunc
	C      CalculationFunc
}

func (Func0) AddErrorAction added in v0.260428.0

func (f Func0) AddErrorAction(code string, d Doer, skipMain bool)

func (Func0) Calculation added in v0.250114.0

func (f Func0) Calculation() float64

func (Func0) Do

func (f Func0) Do(ctx context.Context) error

func (Func0) FixErrorAction added in v0.260428.0

func (f Func0) FixErrorAction(code string) Doer

func (Func0) String

func (f Func0) String() string

func (Func0) Validate

func (f Func0) Validate() error

type FuncArg

type FuncArg struct {
	Name   string
	F      func(context.Context, Arg) error
	ErrorF map[string]Doer
	V      ValidateFunc
	C      CalculationFunc
	// contains filtered or unexported fields
}

func (FuncArg) AddErrorAction added in v0.260428.0

func (fa FuncArg) AddErrorAction(code string, d Doer, skipMain bool)

func (FuncArg) Apply

func (fa FuncArg) Apply(a Arg) (Doer, bool, error)

func (FuncArg) Calculation added in v0.250114.0

func (fa FuncArg) Calculation() float64

func (FuncArg) Do

func (fa FuncArg) Do(ctx context.Context) error

func (FuncArg) FixErrorAction added in v0.260428.0

func (fa FuncArg) FixErrorAction(code string) Doer

FixErrorAction implements Doer.

func (FuncArg) String

func (fa FuncArg) String() string

func (FuncArg) Validate

func (fa FuncArg) Validate() error

type IgnoreArg

type IgnoreArg struct{ Doer }

func (IgnoreArg) Apply

func (i IgnoreArg) Apply(Arg) (Doer, bool, error)

type Lazy

type Lazy struct {
	Name string

	// ErrorF map[int32]func(context.Context) error
	ErrorF map[string]Doer
	// contains filtered or unexported fields
}

func (*Lazy) AddErrorAction added in v0.260428.0

func (l *Lazy) AddErrorAction(code string, d Doer, skipMain bool)

AddErrorAction implements Doer.

func (*Lazy) Calculation added in v0.250114.0

func (l *Lazy) Calculation() float64

func (*Lazy) Do

func (l *Lazy) Do(ctx context.Context) error

func (*Lazy) FixErrorAction added in v0.260428.0

func (l *Lazy) FixErrorAction(code string) Doer

FixErrorAction implements Doer.

func (*Lazy) Force

func (l *Lazy) Force() (d Doer, forced bool, err error)

func (*Lazy) String

func (l *Lazy) String() string

func (*Lazy) Validate

func (l *Lazy) Validate() error

type MaybeBool

type MaybeBool uint8

type Nothing

type Nothing struct{ Name string }

func (Nothing) AddErrorAction added in v0.260428.0

func (n Nothing) AddErrorAction(code string, d Doer, skipMain bool)

func (Nothing) Calculation added in v0.250114.0

func (n Nothing) Calculation() float64

func (Nothing) Do

func (n Nothing) Do(ctx context.Context) error

func (Nothing) FixErrorAction added in v0.260428.0

func (n Nothing) FixErrorAction(code string) Doer

func (Nothing) String

func (n Nothing) String() string

func (Nothing) Validate

func (n Nothing) Validate() error

type ProfileFunc

type ProfileFunc func(Doer, time.Duration)

type RepeatN

type RepeatN struct {
	N uint
	D Doer
}

func (RepeatN) AddErrorAction added in v0.260428.0

func (r RepeatN) AddErrorAction(code string, d Doer, skipMain bool)

func (RepeatN) Calculation added in v0.250114.0

func (r RepeatN) Calculation() float64

func (RepeatN) Do

func (r RepeatN) Do(ctx context.Context) error

func (RepeatN) FixErrorAction added in v0.260428.0

func (r RepeatN) FixErrorAction(code string) Doer

func (RepeatN) String

func (r RepeatN) String() string

func (RepeatN) Validate

func (r RepeatN) Validate() error

type RestartError

type RestartError struct {
	Doer
	Check func(error) bool
	Reset Doer
}

func (*RestartError) Apply

func (rse *RestartError) Apply(arg Arg) (Doer, bool, error)

func (*RestartError) Calculation added in v0.250114.0

func (re *RestartError) Calculation() float64

func (*RestartError) Do

func (re *RestartError) Do(ctx context.Context) error

func (*RestartError) String

func (re *RestartError) String() string

func (*RestartError) Validate

func (re *RestartError) Validate() error

type Seq

type Seq struct {
	ErrorActions map[string]ErrorActionEntry
	// contains filtered or unexported fields
}

Sequence executor. Specialized version of Tree for performance. Error in one action aborts whole group. Build graph with NewSeq().Append()

func NewSeq

func NewSeq(name string, items ...int) *Seq

func (*Seq) AddErrorAction added in v0.260428.0

func (seq *Seq) AddErrorAction(code string, d Doer, skipMain bool)

func (*Seq) Append

func (seq *Seq) Append(d Doer) *Seq

func (*Seq) Apply

func (seq *Seq) Apply(arg Arg) (Doer, bool, error)

Apply makes copy of Seq, applying `arg` to exactly one (first) placeholder.

func (*Seq) Calculation added in v0.250114.0

func (seq *Seq) Calculation() (summ float64)

func (*Seq) Do

func (seq *Seq) Do(ctx context.Context) error

func (*Seq) FixErrorAction added in v0.260428.0

func (seq *Seq) FixErrorAction(errorCode string) Doer

FixErrorAction returns Doer for error string matching regex keys. If no Doer matches, returns nil. add action after fixing error

func (*Seq) Force

func (seq *Seq) Force() (Doer, bool, error)

func (*Seq) String

func (seq *Seq) String() string

func (*Seq) Validate

func (seq *Seq) Validate() (err error)

type Sleep

type Sleep struct{ time.Duration }

func (Sleep) AddErrorAction added in v0.260428.0

func (s Sleep) AddErrorAction(code string, d Doer, skipMain bool)

func (Sleep) Calculation added in v0.250114.0

func (s Sleep) Calculation() float64

func (Sleep) Do

func (s Sleep) Do(ctx context.Context) error

func (Sleep) FixErrorAction added in v0.260428.0

func (s Sleep) FixErrorAction(code string) Doer

func (Sleep) String

func (s Sleep) String() string

func (Sleep) Validate

func (s Sleep) Validate() error

type ValidateFunc

type ValidateFunc func() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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