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
- func ExecutionError(msg string) error
- func ParseJSON(raw []byte) (any, error)
- func ToJSON(v any) ([]byte, error)
- type CallEvent
- type Clock
- type Engine
- type Error
- type ExecutionRequest
- type Expr
- type Frame
- type FuncRef
- type Host
- type LogEntry
- type Program
- type RealClock
- type StepEvent
- type SyntaxError
Constants ¶
const ( CallBegun = "BEGUN" CallSucceeded = "SUCCEEDED" CallExceptionRaised = "EXCEPTION_RAISED" CallExceptionHandled = "EXCEPTION_HANDLED" )
Call event states, as in google.cloud.workflows.type.EngineCallLog.State.
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.
const ( StepInProgress = "STATE_IN_PROGRESS" StepSucceeded = "STATE_SUCCEEDED" StepFailed = "STATE_FAILED" StepCancelled = "STATE_CANCELLED" )
Step entry states.
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.
const ( ProgressFor = "PROGRESS_TYPE_FOR" ProgressParallelFor = "PROGRESS_TYPE_PARALLEL_FOR" ProgressRetry = "PROGRESS_TYPE_RETRY" )
Progress types, as in StepEntryMetadata.ProgressType.
const (
// TagExecutionError is raised when an execution started by experimental.executions fails.
TagExecutionError = "ExecutionError"
)
Variables ¶
This section is empty.
Functions ¶
func ExecutionError ¶
ExecutionError is the error a host returns when an execution it ran finished unsuccessfully.
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 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.
type Error ¶
Error is a workflow error: the value a raise produced or a runtime error map.
func NewError ¶
NewError builds a catchable error map with the given message and tags, for hosts such as connectors.
func NewHTTPError ¶
NewHTTPError builds the error a failed HTTP call raises.
func (*Error) Cancelled ¶
Cancelled reports whether the error is the execution being cancelled rather than a catchable error.
type ExecutionRequest ¶
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.
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 Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a validated workflow.
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 ¶
SyntaxError is a workflow that fails validation at deploy time.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string