wfinterp

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 32 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wfinterp is an interpreter for the Google Cloud Workflows language: YAML or JSON workflow sources, ${...} expressions and the standard library. It performs no I/O of its own; time, HTTP, logging, callbacks and connectors come from a Host.

Index

Constants

View Source
const (
	CallBegun            = "BEGUN"
	CallSucceeded        = "SUCCEEDED"
	CallExceptionRaised  = "EXCEPTION_RAISED"
	CallExceptionHandled = "EXCEPTION_HANDLED"
)

Call event states, as in google.cloud.workflows.type.EngineCallLog.State.

View Source
const (
	TagTypeError          = "TypeError"
	TagValueError         = "ValueError"
	TagKeyError           = "KeyError"
	TagIndexError         = "IndexError"
	TagZeroDivisionError  = "ZeroDivisionError"
	TagArithmeticError    = "ArithmeticError"
	TagHTTPError          = "HttpError"
	TagConnectionError    = "ConnectionError"
	TagConnectionFailed   = "ConnectionFailedError"
	TagTimeoutError       = "TimeoutError"
	TagRecursionError     = "RecursionError"
	TagResourceLimitError = "ResourceLimitError"
	TagResponseTypeError  = "ResponseTypeError"
	TagOperationError     = "OperationError"
	TagUnhandledBranch    = "UnhandledBranchError"
	TagRuntimeError       = "RuntimeError"
	TagAuthError          = "AuthError"
	TagSystemError        = "SystemError"
)

Error tags used by the runtime, as listed in the Workflows error reference.

View Source
const (
	StepInProgress = "STATE_IN_PROGRESS"
	StepSucceeded  = "STATE_SUCCEEDED"
	StepFailed     = "STATE_FAILED"
	StepCancelled  = "STATE_CANCELLED"
)

Step entry states.

View Source
const (
	StepTypeAssign        = "STEP_ASSIGN"
	StepTypeStdLibCall    = "STEP_STD_LIB_CALL"
	StepTypeConnectorCall = "STEP_CONNECTOR_CALL"
	StepTypeSubworkflow   = "STEP_SUBWORKFLOW_CALL"
	StepTypeSwitch        = "STEP_SWITCH"
	StepTypeFor           = "STEP_FOR"
	StepTypeParallelFor   = "STEP_PARALLEL_FOR"
	StepTypeParallel      = "STEP_PARALLEL_BRANCH"
	StepTypeTry           = "STEP_TRY_RETRY_EXCEPT"
	StepTypeReturn        = "STEP_RETURN"
	StepTypeRaise         = "STEP_RAISE"
	StepTypeGoto          = "STEP_GOTO"
	StepTypeCondition     = "STEP_CONDITION"
	StepTypeIteration     = "STEP_FOR_ITERATION"
	StepTypeBranchEntry   = "STEP_PARALLEL_BRANCH_ENTRY"
	StepTypeTryPart       = "STEP_TRY"
	StepTypeRetryPart     = "STEP_RETRY"
	StepTypeExceptPart    = "STEP_EXCEPT"
)

Step types, as in google.cloud.workflows.executions.v1.StepEntry.StepType.

View Source
const (
	ProgressFor         = "PROGRESS_TYPE_FOR"
	ProgressParallelFor = "PROGRESS_TYPE_PARALLEL_FOR"
	ProgressRetry       = "PROGRESS_TYPE_RETRY"
)

Progress types, as in StepEntryMetadata.ProgressType.

View Source
const (
	// TagExecutionError is raised when an execution started by experimental.executions fails.
	TagExecutionError = "ExecutionError"
)

Variables

This section is empty.

Functions

func ExecutionError

func ExecutionError(msg string) error

ExecutionError is the error a host returns when an execution it ran finished unsuccessfully.

func ParseJSON

func ParseJSON(raw []byte) (any, error)

ParseJSON decodes JSON into workflow values: integers become int64, other numbers float64.

func ToJSON

func ToJSON(v any) ([]byte, error)

ToJSON encodes a workflow value as JSON; bytes become base64 strings.

Types

type CallEvent

type CallEvent struct {
	Time      time.Time
	CallStart time.Time
	Args      map[string]any
	State     string
	Step      string
	Callee    string
	Response  string
	Exception string
	Origin    string
}

CallEvent describes one stage of a call step.

type Clock

type Clock interface {
	Now() time.Time
	Sleep(ctx context.Context, d time.Duration) error
}

Clock supplies time to a running workflow; tests inject a fake.

type Engine

type Engine struct {

	// KnownConnector reports whether a googleapis.* name can be called; nil accepts every name.
	KnownConnector func(name string) bool
	// contains filtered or unexported fields
}

Engine holds the function library; it is safe for concurrent use.

func NewEngine

func NewEngine() *Engine

NewEngine returns an Engine with the full standard library.

func (*Engine) Compile

func (e *Engine) Compile(src string) (*Program, error)

Compile parses and validates workflow source (YAML or JSON).

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, p *Program, arg any, host *Host) (any, error)

Run executes the main subworkflow with arg as its argument and returns the workflow result.

type Error

type Error struct {
	Value any
	Stack []Frame
	// contains filtered or unexported fields
}

Error is a workflow error: the value a raise produced or a runtime error map.

func NewError

func NewError(msg string, tags ...string) *Error

NewError builds a catchable error map with the given message and tags, for hosts such as connectors.

func NewHTTPError

func NewHTTPError(code int, headers map[string][]string, body any, msg string) *Error

NewHTTPError builds the error a failed HTTP call raises.

func (*Error) Cancelled

func (e *Error) Cancelled() bool

Cancelled reports whether the error is the execution being cancelled rather than a catchable error.

func (*Error) Context

func (e *Error) Context() string

Context renders the position the way Execution.Error.Context shows it.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Payload

func (e *Error) Payload() string

Payload is the error value as JSON.

type ExecutionRequest

type ExecutionRequest struct {
	Argument any
	Workflow string
	Location string
	Project  string
}

ExecutionRequest is one execution started by experimental.executions.run or map.

type Expr

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

Expr is a parsed ${...} expression.

func ParseExpr

func ParseExpr(src string) (*Expr, error)

ParseExpr parses expression source (without the ${ } wrapper).

func (*Expr) Source

func (e *Expr) Source() string

Source returns the expression text without the ${ } wrapper.

type Frame

type Frame struct {
	Routine string
	Step    string
	Line    int
}

Frame is one position in a workflow: a step of a routine.

type FuncRef

type FuncRef struct{ Name string }

FuncRef is a reference to a named function or subworkflow, as produced by ${http.default_retry_predicate}.

type Host

type Host struct {
	Clock Clock
	HTTP  *http.Client
	// Env resolves sys.get_env names.
	Env func(name string) (string, bool)
	// Log receives sys.log output.
	Log func(LogEntry)
	// Token returns a bearer token for http auth (kind is "OIDC" or "OAuth2").
	Token func(kind, audience, scope, target string) string
	// Connector runs a googleapis.* call; handled is false for an unknown connector.
	Connector func(ctx context.Context, name string, args map[string]any) (result any, handled bool, err error)
	// CreateCallback returns the URL callers POST to in order to resume events.await_callback.
	CreateCallback func(ctx context.Context, method string) (url string, err error)
	// AwaitCallback blocks until the callback at url is called or ctx ends.
	AwaitCallback func(ctx context.Context, url string) (map[string]any, error)
	// RunExecutions starts one execution per request, waits for all of them and returns their results in order.
	RunExecutions func(ctx context.Context, reqs []ExecutionRequest) ([]any, error)
	// CallLog receives one event per explicit call step when set.
	CallLog func(CallEvent)
	// Progress is told which steps are executing each time they change.
	Progress func([]Frame)
	// StepLog receives an event when every step starts and when it finishes.
	StepLog func(StepEvent)
	// StepBudget is asked before each step whether to emit its events and whether to snapshot its variables, so a
	// consumer that has stopped recording does not pay for events it would drop. Nil means both.
	StepBudget func() (log, vars bool)
	// StepVariables adds the visible variables to the finish events of StepLog.
	StepVariables bool
}

Host connects a running workflow to its surroundings. Every field is optional.

type LogEntry

type LogEntry struct {
	JSON     map[string]any
	Severity string
	Text     string
}

LogEntry is one sys.log call.

type Program

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

Program is a validated workflow.

type RealClock

type RealClock struct{}

RealClock is the wall clock.

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current time.

func (RealClock) Sleep

func (RealClock) Sleep(ctx context.Context, d time.Duration) error

Sleep waits for d or until ctx is done.

type StepEvent

type StepEvent struct {
	Time time.Time
	// Vars holds the variables visible to the step when it finished, only when Host.StepVariables is set.
	Vars      map[string]any
	State     string
	Routine   string
	Step      string
	Type      string
	Exception string
	// ProgressType, Progress and Expected describe an iteration or retry entry: its kind, 1-based position and
	// the expected count (0 when unbounded or unknown).
	ProgressType string
	Progress     int64
	Expected     int64
	ID           int64
	// Parent is the entry of the step that encloses this one or called its subworkflow; 0 at the top.
	Parent int64
	// Prev is the entry of the step that ran just before this one in the same block; 0 for the first.
	Prev   int64
	Thread int
}

StepEvent reports a step starting (State StepInProgress) or finishing; both carry the same ID.

type SyntaxError

type SyntaxError struct {
	Routine string
	Step    string
	Msg     string
	Line    int
}

SyntaxError is a workflow that fails validation at deploy time.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Jump to

Keyboard shortcuts

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