Documentation
¶
Overview ¶
Package states implements the State behavior for the workflow states are the basic step in the workflow, they can be combined to form a complex workflow
Index ¶
- Variables
- func HasIntersection(x []string, y []string) bool
- func IsExecutableStateType(stype string) bool
- func ParserStateMachine(definition string) error
- func RegisterResource(resource string)
- func ValidateStateFieldOptional(data map[string]any) error
- type BaseBone
- type BaseState
- func (s *BaseState) GenParameters(input any) (any, error)
- func (s *BaseState) GetBone() StateBone
- func (s *BaseState) GetName() string
- func (s *BaseState) GetNextState(input any, output any) (NextState, error)
- func (s *BaseState) GetOutput(input any, output any) (any, error)
- func (s *BaseState) GetOutputWithPath(input any, output any, resultpath string, outputpath string) (any, error)
- func (s *BaseState) GetParametersInput(input any) (any, error)
- func (s *BaseState) GetType() string
- func (s *BaseState) Init() error
- func (s *BaseState) RenderParameters(input any, parameters any) (any, error)
- func (s *BaseState) SetName(name string)
- func (s *BaseState) Validate() error
- type Choice
- type ChoiceBody
- type ChoiceBranch
- type FieldError
- type FiledPathError
- type NextState
- type Pass
- type PassBody
- type QueryLanguageType
- type ResourceURI
- type State
- type StateBone
- type StateFieldRequired
- type StateMachine
- type StateMachineBody
- type StateMachineBone
- type StateMachineHeader
- type StateType
- type Task
- type TaskBody
- type TaskCatchNode
- type TaskRetryNode
- type TaskSendData
- type TaskTimeout
- type Wait
- type WaitBody
Constants ¶
This section is empty.
Variables ¶
var ( ErrorLackOfRequiredField = errors.New("lack of required field") ErrorInvalidStateType = errors.New("invalid state type") ErrorInvalidFiledContent = errors.New("field content is invalid") ErrorFiledDenied = errors.New("field is dentied") ErrorFiledRequired = errors.New("field is required") ErrorInvalidData = errors.New("invalid data") ErrorInvalidField = errors.New("invalid field") )
ErrorLackOfRequiredField ...
var CommonFields = []string{ StateFieldNames.Comment, StateFieldNames.InputPath, StateFieldNames.OutputPath, StateFieldNames.Parameters, StateFieldNames.ResultPath, }
CommonFields common fields
var DefaultCatchNode = TaskCatchNode{ ErrorEquals: []string{}, Next: "", ResultPath: "$", }
DefaultCatchNode default catch config for task
var DefaultRetryNode = TaskRetryNode{ ErrorEquals: []string{}, IntervalSeconds: 1, MaxAttempts: 3, BackoffRate: 1.5, }
DefaultRetryNode default retry config for task
var DefaultTaskBody = TaskBody{ Resource: "", TimeoutSeconds: 0, HeartbeatSeconds: 0, Retry: []TaskRetryNode{}, Catch: []TaskCatchNode{}, }
DefaultTaskBody ...
var FiledRequiredLevel = struct { Allowed int Required int Deny int }{ Allowed: 0, Required: 1, Deny: 2, }
FiledRequiredLevel field required level
var HeaderFieldNames = struct { Version string Type string Comment string QueryLanguage string }{ Version: "Version", Type: "Type", Comment: "Comment", QueryLanguage: "QueryLanguage", }
HeaderFieldNames ...
var QueryLanguages = struct { JSONPath QueryLanguageType JSONata QueryLanguageType }{ JSONPath: "JSONPath", JSONata: "JSONata", }
QueryLanguages ...
var ResourceSeparator = ":"
ResourceSeparator ...
var ResourceType = struct { Builtin string Activity string }{ Activity: "activity", Builtin: "builtin", }
ResourceType 资源类型
var StateFieldNames = struct { Type string Comment string InputPath string OutputPath string Parameters string ResultPath string Next string End string Resource string Retry string Catch string TimeoutSeconds string HeartbeatSeconds string }{ Type: "Type", Comment: "Comment", InputPath: "InputPath", OutputPath: "OutputPath", Parameters: "Parameters", ResultPath: "ResultPath", Next: "Next", End: "End", Resource: "Resource", Retry: "Retry", Catch: "Catch", TimeoutSeconds: "TimeoutSeconds", HeartbeatSeconds: "HeartbeatSeconds", }
StateFieldNames common field names
var StateFieldRequiredMap = map[StateType]StateFieldRequired{ StateTypes.Task: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Required, }, StateTypes.Parallel: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Required, }, StateTypes.Map: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Required, }, StateTypes.Pass: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Required, Retry: FiledRequiredLevel.Deny, Catch: FiledRequiredLevel.Deny, }, StateTypes.Wait: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Required, ResultPath: FiledRequiredLevel.Deny, Parameters: FiledRequiredLevel.Deny, Retry: FiledRequiredLevel.Deny, Catch: FiledRequiredLevel.Deny, }, StateTypes.Choice: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Deny, ResultPath: FiledRequiredLevel.Deny, Parameters: FiledRequiredLevel.Deny, Retry: FiledRequiredLevel.Deny, Catch: FiledRequiredLevel.Deny, }, StateTypes.Succeed: { Type: FiledRequiredLevel.Required, NextEnd: FiledRequiredLevel.Deny, ResultPath: FiledRequiredLevel.Deny, Parameters: FiledRequiredLevel.Deny, Retry: FiledRequiredLevel.Deny, Catch: FiledRequiredLevel.Deny, }, StateTypes.Fail: { Type: FiledRequiredLevel.Required, InputPath: FiledRequiredLevel.Deny, OutputPath: FiledRequiredLevel.Deny, NextEnd: FiledRequiredLevel.Deny, ResultPath: FiledRequiredLevel.Deny, Parameters: FiledRequiredLevel.Deny, Retry: FiledRequiredLevel.Deny, Catch: FiledRequiredLevel.Deny, }, StateTypes.Suspend: { Type: FiledRequiredLevel.Required, InputPath: FiledRequiredLevel.Deny, OutputPath: FiledRequiredLevel.Deny, NextEnd: FiledRequiredLevel.Deny, ResultPath: FiledRequiredLevel.Deny, Parameters: FiledRequiredLevel.Deny, Retry: FiledRequiredLevel.Deny, Catch: FiledRequiredLevel.Deny, }, StateTypes.StateGroup: {}, }
StateFieldRequiredMap field required map
var StateMachineFieldNames = struct { StartAt string States string }{ StartAt: "StartAt", States: "States", }
var StateMachineType = "statemachine"
StateMachineType ...
var StateTypes = struct { Task StateType Choice StateType Fail StateType Succeed StateType Wait StateType Pass StateType Parallel StateType Map StateType Suspend StateType // 子流程类型, Parallel/Map 生成的中间步骤 StateGroup StateType }{ Task: "Task", Choice: "Choice", Fail: "Fail", Succeed: "Succeed", Wait: "Wait", Pass: "Pass", Parallel: "Parallel", Map: "Map", Suspend: "Suspend", StateGroup: "StateGroup", }
StateTypes constant State type define here
var TimeFormatCommon = "2006-01-02 15:04:05"
var TimeFormatList = []string{TimeFormatCommon, time.RFC3339}
var VariablePrefix = "$."
VariablePrefix 变量字段的前缀
Functions ¶
func HasIntersection ¶
HasIntersection return if x and y have common elements
func IsExecutableStateType ¶
IsExecutableStateType 是否是可执行的步骤类型
func ValidateStateFieldOptional ¶
ValidateStateFieldOptional validate state field optional
Types ¶
type BaseBone ¶
type BaseBone struct {
Type string `json:"Type"`
Name string `json:"Name"`
Next []string `json:"Next"`
End bool `json:"End"`
Comment string `json:"Comment"`
}
BaseBone common state type bone
type BaseState ¶
type BaseState struct {
Name string `json:"Name,omitempty"`
Type string `json:"Type,omitempty"`
Comment string `json:"Comment,omitempty"`
InputPath string `json:"InputPath,omitempty"`
OutputPath string `json:"OutputPath,omitempty"`
ResultPath string `json:"ResultPath,omitempty"`
Parameters any `json:"Parameters,omitempty"`
MaxExecuteTimes int `json:"MaxExecuteTimes,omitempty"`
End bool `json:"End,omitempty"`
Next string `json:"Next,omitempty"`
Retry any `json:"Retry,omitempty"`
Catch any `json:"Catch,omitempty"`
}
BaseState is a struct that defines the base state of a state machine, with default values
func (*BaseState) GenParameters ¶
GenParameters calculate parameters by input data and parameters @input input state origin input return parameters
func (*BaseState) GetNextState ¶
GetNextState get next state info generate final output using inputpath parameters resultpath outputpath @input state origin input @output state produce data return next state info
func (*BaseState) GetOutput ¶
GetOutput calculate task output cautions: 1. return nil if outputpath is empty 2. return output is not a copy of input, it will reference data from input and output, which is defined in resultpath and outputpath @input input state origin input @output output state produce data return output state produce data
func (*BaseState) GetOutputWithPath ¶
func (s *BaseState) GetOutputWithPath(input any, output any, resultpath string, outputpath string) (any, error)
GetOutputWithPath calculate output with resultpath and outputpath cautions: 1. return nil if outputpath is empty 2. return output is not a copy of input, it will reference data from input and output, which is defined in resultpath and outputpath @input input state origin input @output output state produce data @resultpath resultpath @outputpath outputpath
func (*BaseState) GetParametersInput ¶
GetParametersInput get state parameters input input , origin input, output state input using inputpath , parameters
func (*BaseState) RenderParameters ¶
RenderParameters render parameters @input input state origin input @parameters parameters field parameters return parameters
type Choice ¶
type Choice struct {
*BaseState
*ChoiceBody
}
Choice ...
func (*Choice) ChoiceNextState ¶
ChoiceNextState
func (*Choice) GetNextState ¶
GetNextState Get Next State input state origin input
type ChoiceBody ¶
type ChoiceBody struct {
Choices []ChoiceBranch `mapstructure:"Choices"`
Default string `mapstructure:"Default" validate:"gte=0"`
}
ChoiceBody ...
type ChoiceBranch ¶
type ChoiceBranch struct {
Condition expression.BooleanExpression
Next string `mapstructure:"Next" validate:"required,gt=0"`
}
type FieldError ¶
type FieldError struct {
// The error that occurred
RawError error
Line int64
Column int64
Offset int64
Paths []string
}
FieldError is an error that occurred in a field at a specific path or line number and column number or offset in the file. FieldError is final state error for FieldPathError.
func NewFieldPathError ¶
func NewFieldPathError(err error, paths ...string) *FieldError
NewFieldPathError ...
type FiledPathError ¶
FiledPathError FieldPathError is an error that occurred in a field at a specific path.
type NextState ¶
type NextState struct {
Name string // Next State Name
Output interface{} // State Output as the input of the next state
Delay time.Duration // Delay delay duration from current state to next state
Retry bool // Whether to trigger retry
RetryIndex int // Which Indexed Retry strategy hit
}
NextState next state info
type ResourceURI ¶
ResourceURI resource uri defintion
func ParseResource ¶
func ParseResource(resource string) (uri *ResourceURI, err error)
ParseResource parser path to ResourceURI
type State ¶
type State interface {
Init() error
Validate() error
GetName() string
SetName(name string)
GetType() string
GetBone() StateBone
}
State ...
type StateBone ¶
type StateBone struct {
BaseBone
*StateMachineBone
Branches []StateBone `json:"Branches"`
}
StateBone for map /parallel state bone
type StateFieldRequired ¶
type StateFieldRequired struct {
Comment int
Type int
InputPath int
OutputPath int
Parameters int
ResultPath int
NextEnd int
Retry int
Catch int
}
StateFieldRequired state field required
type StateMachine ¶
type StateMachine struct {
*StateMachineHeader
*StateMachineBody
}
StateMachine ...
type StateMachineBody ¶
StateMachineBody ...
func (*StateMachineBody) GetBone ¶
func (s *StateMachineBody) GetBone() StateMachineBone
func (*StateMachineBody) SetStartAt ¶
func (s *StateMachineBody) SetStartAt(name string)
type StateMachineBone ¶
type StateMachineBone struct {
StartAt string `json:"StartAt"`
States map[string]StateBone `json:"States"`
}
StateMachineBone StateMachineBone
type StateMachineHeader ¶
StateMachineHeader ...
type Task ¶
Task ...
func (*Task) GetNextState ¶
func (t *Task) GetNextState(input interface{}, taskdata TaskSendData) (NextState, error)
GetNextState get task next state @input state input data @taskdata task send data return next state
func (*Task) GetTaskTimeout ¶
func (t *Task) GetTaskTimeout() (TaskTimeout, error)
GetTaskTimeout return task timeout
type TaskBody ¶
type TaskBody struct {
Resource string `validate:"required,gt=0"`
TimeoutSeconds uint `validate:"gte=0"`
HeartbeatSeconds uint `validate:"gte=0"`
// Retry for decode
Retry []TaskRetryNode `mapstructure:"Retry"`
// Catch for decode
Catch []TaskCatchNode `mapstructure:"Catch"`
}
TaskBody ...
type TaskCatchNode ¶
type TaskCatchNode struct {
ErrorEquals []string `mapstructure:"ErrorEquals"`
Next string `mapstructure:"Next"`
ResultPath string `mapstructure:"ResultPath"`
}
TaskCatchNode struct for catch
type TaskRetryNode ¶
type TaskRetryNode struct {
ErrorEquals []string `mapstructure:"ErrorEquals"`
IntervalSeconds uint `mapstructure:"IntervalSeconds"`
MaxAttempts uint `mapstructure:"MaxAttempts"`
BackoffRate float64 `mapstructure:"BackoffRate"`
}
TaskRetryNode struct for retry
type TaskSendData ¶
type TaskSendData struct {
Success bool // is task submit success
Retry []int // current retry times, index is retry times for each Retry branch
Errors []string // send error list
Output any // task state execute output
}
TaskSendData task state execute and send data
type TaskTimeout ¶
TaskTimeout Describe Task Timeout demand
type Wait ¶
Wait ...
func (*Wait) GetNextState ¶
GetNextState Get Next State
func (*Wait) GetWakeupTime ¶
GetWakeupTime Get Wait State Wake up time
type WaitBody ¶
type WaitBody struct {
Seconds uint `mapstructure:"Seconds" validate:"gte=0"`
Timestamp string `mapstructure:"Timestamp" validate:"gte=0"`
SecondsPath string `mapstructure:"SecondsPath" validate:"gte=0"`
TimestampPath string `mapstructure:"TimestampPath" validate:"gte=0"`
}
WaitBody ...