autoflow

package
v19.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxFlowSteps uint64 = 100_000_000

DefaultMaxFlowSteps is the step budget of a flow thread when the options set none, in Starlark computation steps (roughly one per bytecode instruction). Each thread of a flow run has its own budget; a warm resume carries the count and a cold replay reproduces it, so a runaway fails at the same instruction wherever it runs, while the CPU a cold replay re-spends re-executing history stays unbounded. It is a guard against a runaway rather than a budget an author plans for: around a second of CPU.

Variables

This section is empty.

Functions

func ContextFromThread

func ContextFromThread(thread *starlark.Thread) context.Context

func ExecFunc added in v19.3.0

func ExecFunc(ctx context.Context, fn starlark.Value, opts *ExecFuncOptions) (starlark.Value, error)

func ExecMain added in v19.3.0

func ExecMain(ctx context.Context, opts *ExecMainOptions) (starlark.Value, error)

ExecMain runs a Starlark script that must define a top-level entry function (`main`, unless EntryFunction names another one), then calls it as `entry(w, *Args, **Kwargs)` and returns the value it produces (which is `starlark.None` when it has no explicit return). The entry function's signature determines which arguments it accepts; supplying an argument it does not declare is an error.

func ExecScript

func ExecScript(ctx context.Context, opts *ExecScriptOptions) (starlark.StringDict, error)

ExecScript runs a Starlark script and returns the top-level symbols it defines.

func NewFileOptions added in v19.3.0

func NewFileOptions() *syntax.FileOptions

NewFileOptions returns the Starlark dialect options AutoFlow parses and executes scripts with. Callers that evaluate script-adjacent input, such as CLI --arg/--kwarg expressions, use these so the input parses identically.

Types

type Action added in v19.3.0

type Action interface {
	starlark.Callable
	// Poll invokes the action repeatedly until check (a CEL expression over the
	// action's returned value, bound as `ret`) is satisfied, re-attempting every
	// interval until timeout elapses. The returned Future yields the action's
	// value on success, or timeoutValue once timeout elapses without check
	// passing.
	Poll(
		ctx context.Context,
		check string,
		args starlark.Tuple,
		kwargs []starlark.Tuple,
		interval, timeout time.Duration,
		timeoutValue starlark.Value,
	) (Future, error)
}

Action is a Starlark callable bound to a module action, one per action the loaded module exports. Unlike an ordinary callable, the runtime can schedule its invocation over time rather than perform it inline, which is what poll() needs.

type ActionDeriver added in v19.3.0

type ActionDeriver interface {
	// DeriveAction returns an action that invokes action from within transform, so
	// what reaches action is what transform passes on and what the derived action
	// yields is transform's own output. script is the file the transform was
	// declared in, which is what the runtime needs to recover the transform's
	// source text.
	DeriveAction(action Action, transform *starlark.Function, script Script) (Action, error)
}

ActionDeriver derives an action from an existing action plus a pure Starlark transform wrapping its invocation, so the transform settles the arguments the action is invoked with as well as the value the derived action yields. The language layer only carries the declaration: validating the transform, pinning its source and running it are the runtime's business.

type Awaitable added in v19.3.0

type Awaitable interface {
	// Await blocks until a value is available and returns it. A Future yields its
	// single result; a Channel yields its next value and may be awaited again.
	Await() (starlark.Value, error)
}

Awaitable is a source of values a script can wait on: a Future or a Channel. select() and gather() accept either, so they carry this rather than one concrete kind.

type Backend

type Backend interface {
	SetLocals(*starlark.Thread)
	Print(msg string)
	// Select blocks until one of the cases is ready and returns that case's name.
	// If timeout is non-zero and elapses first, it returns timeoutValue.
	Select(ctx context.Context, cases []SelectCase, timeout time.Duration, timeoutValue starlark.Value) (starlark.Value, error)
	// NewChannel constructs a new channel that yields successive values over time.
	NewChannel() Channel
	Sleep(ctx context.Context, duration time.Duration) error
	Timer(duration time.Duration) Future
	WorkflowKey() string
	// Gather waits for all given sources. If returnList is false it returns the
	// single source's value, otherwise a starlark.List of values. If timeout is
	// non-zero and elapses before all sources are ready, it returns timeoutValue
	// instead of a result.
	Gather(ctx context.Context, sources []Awaitable, timeout time.Duration, timeoutValue starlark.Value, returnList bool) (starlark.Value, error)
	// StartWorkflow schedules a fire-and-forget child workflow that runs the given
	// code with the given positional and keyword arguments. It returns the child's
	// workflow key.
	//
	// Exactly one of definition and entryFunction is set: a non-nil definition is
	// a self-contained script whose entry point is main, while an entryFunction
	// makes the child run the calling workflow's own definition with that
	// top-level function as its entry point.
	StartWorkflow(ctx context.Context, definition []byte, entryFunction string, args starlark.Tuple, kwargs []starlark.Tuple) (string, error)
	// ExecuteWorkflow schedules an awaitable child workflow that runs the given
	// code with the given positional and keyword arguments. The returned Future
	// resolves to the child's result; the returned string is the child's workflow
	// key. definition and entryFunction work as in StartWorkflow.
	ExecuteWorkflow(ctx context.Context, definition []byte, entryFunction string, args starlark.Tuple, kwargs []starlark.Tuple) (Future, string, error)
}

Backend is the interface of AutoFlow backend implementation.

type Channel added in v19.2.0

type Channel interface {
	Awaitable
	// Name is the channel's identity.
	Name() string
}

Channel is a result of an asynchronous operation that yields zero or more values over time, similar to a Go channel. Await may be called repeatedly to obtain successive values.

type ChannelType added in v19.2.0

type ChannelType struct {
	C Channel
}

ChannelType is the Starlark representation of a channel.

func (*ChannelType) Attr added in v19.3.0

func (c *ChannelType) Attr(name string) (starlark.Value, error)

Attr returns the value of the named attribute, or nil if there is no such attribute. Returning nil lets Starlark produce the standard "no such field" error.

func (*ChannelType) AttrNames added in v19.3.0

func (c *ChannelType) AttrNames() []string

AttrNames returns a new slice each time because dir() sorts the result in place.

func (*ChannelType) Freeze added in v19.2.0

func (c *ChannelType) Freeze()

func (*ChannelType) Hash added in v19.2.0

func (c *ChannelType) Hash() (uint32, error)

func (*ChannelType) String added in v19.2.0

func (c *ChannelType) String() string

func (*ChannelType) Truth added in v19.2.0

func (c *ChannelType) Truth() starlark.Bool

func (*ChannelType) Type added in v19.2.0

func (c *ChannelType) Type() string

type ExecFuncOptions added in v19.3.0

type ExecFuncOptions struct {
	Backend Backend
	Tracer  trace.Tracer
	// Globals are the top-level symbols of the flow definition fn belongs to.
	// The child workflow builtins validate function references against them:
	// a child resolves its entry point by name in these globals.
	Globals starlark.StringDict
	// Args and Kwargs are the positional and keyword arguments bound to the
	// fn's parameters, i.e. fn(w, *Args, **Kwargs). Each Kwargs
	// tuple is a (name, value) pair.
	// w is always prepended as the first argument.
	Args   []starlark.Value
	Kwargs []starlark.Tuple
	// MaxSteps is the computation-step budget of the thread fn runs on; zero means
	// the default.
	MaxSteps uint64
	// OnThreadEnd, when set, is called once the thread finished.
	OnThreadEnd ThreadEndFunc
}

type ExecMainOptions added in v19.3.0

type ExecMainOptions struct {
	Definition []byte
	Loader     Loader
	Backend    Backend
	Tracer     trace.Tracer
	// ActionDeriver derives actions for derived_action.
	ActionDeriver ActionDeriver
	// EntryFunction is the name of the top-level function to call. Empty means
	// `main`.
	EntryFunction string
	// Args and Kwargs are the positional and keyword arguments bound to the
	// main's parameters, i.e. main(w, *Args, **Kwargs). Each Kwargs
	// tuple is a (name, value) pair.
	Args   []starlark.Value
	Kwargs []starlark.Tuple
	// MaxSteps is the computation-step budget of the two threads the run builds,
	// the top level's and the entry function's; zero means the default.
	MaxSteps uint64
	// OnThreadEnd, when set, is called once each of those threads finished.
	OnThreadEnd ThreadEndFunc
}

type ExecScriptOptions

type ExecScriptOptions struct {
	ScriptName string
	Definition []byte
	Loader     Loader
	Backend    Backend
	Tracer     trace.Tracer
	// ActionDeriver derives actions for derived_action.
	ActionDeriver ActionDeriver
	// MaxSteps is the computation-step budget of the thread this script runs on;
	// zero means the default.
	MaxSteps uint64
	// Thread is which of the run's threads this script runs on: the flow file's
	// top level (the zero value) or a loaded module file.
	Thread ThreadKind
	// OnThreadEnd, when set, is called once the thread finished.
	OnThreadEnd ThreadEndFunc
}

type Future

type Future interface {
	Awaitable
}

Future is the result of an asynchronous operation that completes once, as opposed to a Channel, which yields successive values. Go cannot express that difference in the method set, so the two are structurally identical to Awaitable and the distinction is carried by the name and by what returns one.

type FutureType

type FutureType struct {
	F Future
}

func (*FutureType) Freeze

func (f *FutureType) Freeze()

func (*FutureType) Hash

func (f *FutureType) Hash() (uint32, error)

func (*FutureType) String

func (f *FutureType) String() string

func (*FutureType) Truth

func (f *FutureType) Truth() starlark.Bool

func (*FutureType) Type

func (f *FutureType) Type() string

type Loader added in v19.3.0

type Loader interface {
	Load(ctx context.Context, thread *starlark.Thread, moduleURI string) (starlark.StringDict, error)
}

type Script added in v19.3.0

type Script struct {
	Name   string
	Source []byte
}

Script is a Starlark file: the name it reports positions under and its source.

type SelectCase added in v19.2.0

type SelectCase struct {
	Name string
	// Source is the value the case waits on.
	Source Awaitable
}

type StepLimitError added in v19.4.0

type StepLimitError struct {
	Thread   string
	Steps    uint64
	Function string
	Pos      syntax.Position
	Err      error
}

StepLimitError is the failure of a flow thread that spent its whole step budget. Function and Pos are the instruction it was stopped at.

func (*StepLimitError) Error added in v19.4.0

func (e *StepLimitError) Error() string

func (*StepLimitError) Unwrap added in v19.4.0

func (e *StepLimitError) Unwrap() error

type ThreadEndFunc added in v19.4.0

type ThreadEndFunc func(ctx context.Context, thread ThreadKind, steps uint64)

ThreadEndFunc receives the computation steps a thread executed once it finished. A thread the round's abort stopped is not reported.

type ThreadKind added in v19.4.0

type ThreadKind string

ThreadKind is which of a flow run's threads a Starlark thread is.

const (
	// ThreadTopLevel runs the flow file's top level.
	ThreadTopLevel ThreadKind = "top_level"
	// ThreadEntry runs the entry function.
	ThreadEntry ThreadKind = "entry"
	// ThreadModule runs a loaded module file.
	ThreadModule ThreadKind = "module"
)

Jump to

Keyboard shortcuts

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