exec

package
v0.8.18 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package exec implements an interpreter of the FSE grammar on top of temporal.io

Index

Constants

View Source
const (
	// QueryWorkflowWFState is the query to retreive an fse interpreter's complete state's name. The query has no parameters.
	QueryWorkflowWFState = "wfstate"
	// QueryWorkflowWFStateFor is the query to retreive an fse interpreter's state for particular roles's name. The query has a single []string argument, the roles.
	QueryWorkflowWFStateFor = "wfstate-for"

	// SignalWorkflowSignalEvent signals a workflow that an external event had happened.
	// Has one parameter of type map[string]string where m[""] is the event's name and all other map values are contextual parameters passed over to all action calls.
	// Available events can be retrieved via QueryWorkflowWFState or QueryWorkflowWFStateForFor in the Triggers result.
	SignalWorkflowSignalEvent = "signal-event"
)
View Source
const (
	// EnvironmentPrevious is the Interpreter's Environment key for the previous state the wf was idle in, $PREVIOUS
	EnvironmentPrevious = `$PREVIOUS`

	// EnvironmentPreviousDisplay is the Interpreter's Environment key for the previous state's display name the wf was idle in, $PREVIOUS
	EnvironmentPreviousDisplay = `$PREVIOUSDISPLAY`

	// EnvironmentEvent is the Interpreter's Environment key for the current signal that is processed, $EVENT
	EnvironmentEvent = `$EVENT`

	// EnvironmentEventDisplay is the Interpreter's Environment key for the current signal's display name that is processed, $EVENT
	EnvironmentEventDisplay = `$EVENTDISPLAY`

	// EnvironmentCurrent is the Interpreter's Environment key for the current state the wf has entered, $CURRENT
	EnvironmentCurrent = `$CURRENT`

	// EnvironmentCurrentDisplay is the Interpreter's Environment key for the current state's display name the wf has entered, $CURRENT
	EnvironmentCurrentDisplay = `$CURRENTDISPLAY`

	// EnvironmentEventTimer is the value bound to $EVENT after a timer event was triggered
	EnvironmentEventTimer = "*timer*"

	// EnvironmentValueNew is the initial value of EnvironmentPrevious/`$PREVIOUS`
	// and its value "*new*" may appear in some logs representing the non-existant
	// state before starting the workflow.
	EnvironmentValueNew = `*new*`
)

Variables

This section is empty.

Functions

func ActionDispatcher

func ActionDispatcher(in *Interpreter, name string, contextualMapAsJSON string, parameters []string) workflow.Future

ActionDispatcher dispatches all named calls to workflow.ExecuteActivity

Types

type Actions

type Actions func(in *Interpreter, name string, contextualMapAsJson string, parameters []string) workflow.Future

Actions is a dispatcher for handling funcalls by name defined as a consequence in an FSE.

type Interpreter

type Interpreter struct {
	WF              *syntax.Workflow
	Ctx             workflow.Context
	Actions         Actions
	Environment     map[string]string
	ActivityOptions workflow.ActivityOptions
	CurrentState    *syntax.State

	Timer             workflow.Future
	TimerConsequences []syntax.Consequence
	TimerDeadline     time.Time
	TimerDuration     time.Duration
	// contains filtered or unexported fields
}

Interpreter is an execution environment for an FSE for termporal.io

func New

func New(ctx workflow.Context, wf *syntax.Workflow, actions Actions) *Interpreter

New creates a new interpreter with an environment for variables for an FSE. If actions is nil, all funcalls are dispatched to tempoaral.io actions that must be either string->string or []string->string according to the parameter list's length of 0 or more accordingly. The first parameter is always a JSON serialized string containing the contextualMap paramters of the create or signal operation.

func (*Interpreter) Run

func (in *Interpreter) Run(initialContextualMap map[string]string) error

Run evaluates an FSE within a temporal.io workflow function. Typical usage is: parse an FSE source, create an Interpreter with an Actions dispatcher func. The initialContextualMap is either nil or initialized by the memo passed to workflow instance creation.

type Named added in v0.5.6

type Named struct {
	Name    string `json:"name"`    // Name is the key of the workflow type or state
	Display string `json:"display"` // Display is a text intended to be shown in a GUI
}

Named pairs a key with a display text

type Resolved

type Resolved string

Resolved implements a resolved workflow.Future of type string

func (Resolved) Get

func (r Resolved) Get(ctx workflow.Context, valuePtr interface{}) error

Get puts r into valuePtr unless valuePtr is nil

func (Resolved) IsReady

func (r Resolved) IsReady() bool

IsReady returns true

type WFState

type WFState struct {
	syntax.Named
	Living        bool                      `json:"living"`
	Idle          bool                      `json:"idle"`
	CurrentAction string                    `json:"currentAction"`
	TaskQueue     string                    `json:"taskqueue"`
	ID            syntax.BusinessWorkflowID `json:"id"`
	Version       syntax.Unversioned        `json:"version"`
	RunID         string                    `json:"runid"`
	CurrentState  syntax.Named              `json:"currentState"`
	Triggers      []syntax.Named            `json:"triggers"`
	TimerDeadline time.Time                 `json:"timerDeadline"`
	Ended         time.Time                 `json:"ended"`
	Environment   map[string]string         `json:"environment"`
}

WFState describes the current fse workflow instance

func Describe

func Describe(in *Interpreter, allTriggers bool, roles []string) (WFState, error)

Describe describes the workflow instance in its current state. If allTriggers is true, all current triggers are returned and roles is ignored. If allTriggers is false only those current triggers are returned that have matching roles in their "for" list.

func (WFState) Env

func (wfs WFState) Env(variable string) string

Env is a convenience function for html/template to replace ((index .Current.Environment "$var")) by ((.Current.Env "$var"))

type WFStateWithSchema added in v0.7.13

type WFStateWithSchema struct {
	WFState
	Schema *syntax.Workflow
}

WFStateWithSchema describes the current fse workflow instance including its Schema

type WFWithStates added in v0.5.6

type WFWithStates struct {
	Named
	Version string  `json:"version"` // Version is the workflow's version string
	Option  string  `json:"option"`  // Option is an option string, that must be parseable via option.Parse
	States  []Named `json:"states"`  // States is the list of states of this workflow
}

WFWithStates records an FSE workflow type's name and a list of state names

Jump to

Keyboard shortcuts

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