states

package
v0.0.0-...-1f88bb8 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 ...

View Source
var ChoiceFieldNames = struct {
	Choices string
	Default string
}{
	Choices: "Choices",
	Default: "Default",
}

ChoiceFieldNames

View Source
var CommonFields = []string{
	StateFieldNames.Comment,
	StateFieldNames.InputPath,
	StateFieldNames.OutputPath,
	StateFieldNames.Parameters,
	StateFieldNames.ResultPath,
}

CommonFields common fields

View Source
var DefaultCatchNode = TaskCatchNode{
	ErrorEquals: []string{},
	Next:        "",
	ResultPath:  "$",
}

DefaultCatchNode default catch config for task

View Source
var DefaultRetryNode = TaskRetryNode{
	ErrorEquals:     []string{},
	IntervalSeconds: 1,
	MaxAttempts:     3,
	BackoffRate:     1.5,
}

DefaultRetryNode default retry config for task

View Source
var DefaultTaskBody = TaskBody{

	Block:    false,
	Resource: "",

	TimeoutSeconds: 0,

	HeartbeatSeconds: 0,

	Retry: []TaskRetryNode{},

	Catch: []TaskCatchNode{},
}

DefaultTaskBody ...

View Source
var FiledRequiredLevel = struct {
	Allowed  int
	Required int
	Deny     int
}{

	Allowed:  0,
	Required: 1,
	Deny:     2,
}

FiledRequiredLevel field required level

View Source
var HeaderFieldNames = struct {
	Version             string
	Type                string
	Comment             string
	QueryLanguage       string
	TimeoutSeconds      string
	AbortTimeoutSeconds string
	ExecutionInfoPath   string
	DefaultInput        string
}{
	Version:             "Version",
	Type:                "Type",
	Comment:             "Comment",
	QueryLanguage:       "QueryLanguage",
	TimeoutSeconds:      "TimeoutSeconds",
	AbortTimeoutSeconds: "AbortTimeoutSeconds",
	ExecutionInfoPath:   "ExecutionInfoPath",
	DefaultInput:        "DefaultInput",
}

HeaderFieldNames ...

View Source
var MaxDepth = 3

StateMachine最大深度,防止流程图过度复杂 MaxDepth 最大深度, 默认为3

View Source
var ParserQuota = config.DefaultQuota
View Source
var QueryLanguages = struct {
	JSONPath QueryLanguageType
	JSONata  QueryLanguageType
}{
	JSONPath: "JSONPath",
	JSONata:  "JSONata",
}

QueryLanguages ...

View Source
var ResourceSeparator = ":"

ResourceSeparator ...

View Source
var ResourceType = struct {
	Builtin    string
	Activity   string
	Kubernetes string
	K8s        string
}{
	Activity:   "activity",
	Builtin:    "builtin",
	Kubernetes: "kubernetes",
	K8s:        "k8s",
}

ResourceType 资源类型

View Source
var StartDepth = 1

StartDepth 最外层的Depth ,默认为1

View Source
var StartGroupID = 1

StartGroupID 最外层的Group ID, 默认为 1

View Source
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

View Source
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

View Source
var StateMachineFieldNames = struct {
	StartAt string
	States  string
}{
	StartAt: "StartAt",
	States:  "States",
}
View Source
var StateMachineType = "statemachine"

StateMachineType ...

View Source
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

View Source
var TimeFormatCommon = "2006-01-02 15:04:05"
View Source
var TimeFormatList = []string{TimeFormatCommon, time.RFC3339}
View Source
var VariablePrefix = "$."

VariablePrefix 变量字段的前缀

Functions

func DecodeMapToStruct

func DecodeMapToStruct(input map[string]interface{}, output interface{}) error

func DecodeStructToMap

func DecodeStructToMap(input interface{}) (map[string]interface{}, error)

func Encoder

func Encoder(v interface{}) ([]byte, error)

Encoder 转码成 bytes

func HasIntersection

func HasIntersection(x []string, y []string) bool

HasIntersection return if x and y have common elements

func InitBaseState

func InitBaseState(bs *BaseState, data map[string]interface{}) error

func InitChoiceBodyByMap

func InitChoiceBodyByMap(body *ChoiceBody, data map[string]interface{}) error

InitByMap Initialize ChoiceState Content

func InitFailBodyByMap

func InitFailBodyByMap(body *FailBody, data map[string]interface{}) error

InitByMap Initialize Fail Content

func InitParallelBodyByMap

func InitParallelBodyByMap(body *ParallelBody, data map[string]interface{}, depth int) error

func InitPassBodyByMap

func InitPassBodyByMap(body *PassBody, data map[string]interface{}) error

InitPassBodyByMap Initialize PassBody Content

func InitStateMachineBodyByMap

func InitStateMachineBodyByMap(smb *StateMachineBody, data map[string]any) (err error)

InitByMap Use map to init StateMachineBody content

func InitStateMachineHeaderByMap

func InitStateMachineHeaderByMap(header *StateMachineHeader, data map[string]interface{}) error

InitByMap 通过Map类型初始化

func InitTaskBodyByMap

func InitTaskBodyByMap(body *TaskBody, data map[string]interface{}) error

InitByMap Initialize TaskState Content

func InitWaitBodyByMap

func InitWaitBodyByMap(body *WaitBody, data map[string]interface{}) (err error)

InitByMap Inititalize Wait Content

func IsExecutableStateType

func IsExecutableStateType(stype string) bool

IsExecutableStateType 是否是可执行的步骤类型

func MapUpdate

func MapUpdate(i map[string]interface{}, toi map[string]interface{})

MapUpdate merge map toi into map object i,

func ParserStateMachine

func ParserStateMachine(definition string) error

ParserStateMachine ...

func RegisterResource

func RegisterResource(resource string)

RegisterResource ...

func StringToMap

func StringToMap(s string) (map[string]interface{}, error)

StringToMap 转换成map

func ToString

func ToString(v interface{}) (string, error)

ToString 转码成string 格式

func ValidateStateFieldOptional

func ValidateStateFieldOptional(data map[string]any) error

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 NewBaseStateFromMap

func NewBaseStateFromMap(data map[string]interface{}) (*BaseState, error)

NewBaseStateFromMap NewState from MapData

func NewBaseStateFromString

func NewBaseStateFromString(definition string) (bs *BaseState, err error)

NewBaseStateFromString New State From String

func NewDefaultBaseState

func NewDefaultBaseState() *BaseState

func (*BaseState) GenParameters

func (s *BaseState) GenParameters(input any) (any, error)

GenParameters calculate parameters by input data and parameters @input input state origin input return parameters

func (*BaseState) GetBone

func (s *BaseState) GetBone() StateBone

GetBone ...

func (*BaseState) GetDefinition

func (bs *BaseState) GetDefinition() (string, error)

func (*BaseState) GetInput

func (s *BaseState) GetInput(input any) (any, error)

GetInput Get State Real Input by InputData input , origin input, output state input using inputpath , parameters

func (*BaseState) GetName

func (s *BaseState) GetName() string

GetName ...

func (*BaseState) GetNext

func (s *BaseState) GetNext() []string

func (*BaseState) GetNextState

func (s *BaseState) GetNextState(input any, output any) (NextState, error)

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

func (s *BaseState) GetOutput(input any, output any) (any, error)

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

func (s *BaseState) GetParametersInput(input any) (any, error)

GetParametersInput get state parameters input input , origin input, output state input using inputpath , parameters

func (*BaseState) GetType

func (s *BaseState) GetType() string

GetType ...

func (*BaseState) Init

func (s *BaseState) Init() error

Init ...

func (*BaseState) IsEnd

func (s *BaseState) IsEnd() bool

func (*BaseState) RenderParameters

func (s *BaseState) RenderParameters(input any, parameters any) (any, error)

RenderParameters render parameters @input input state origin input @parameters parameters field parameters return parameters

func (*BaseState) SetName

func (s *BaseState) SetName(name string)

SetName ...

func (*BaseState) Validate

func (s *BaseState) Validate() error

Validate ...

type ChoiceBody

type ChoiceBody struct {
	Choices []ChoiceBranch `mapstructure:"Choices"`
	Default string         `mapstructure:"Default" validate:"gte=0"`
}

ChoiceBody ...

func NewChoiceBodyFromMap

func NewChoiceBodyFromMap(data map[string]interface{}) (*ChoiceBody, error)

type ChoiceBranch

type ChoiceBranch struct {
	Condition expression.BooleanExpression
	Next      string `mapstructure:"Next" validate:"required,gt=0"`
}

type ChoiceState

type ChoiceState struct {
	*BaseState
	*ChoiceBody
	// contains filtered or unexported fields
}

ChoiceState ...

func NewChoiceStateFromMap

func NewChoiceStateFromMap(data map[string]interface{}) (state *ChoiceState, err error)

NewChoiceStateFromMap NewChoiceStateFromMap

func NewChoiceStateFromString

func NewChoiceStateFromString(definition string) (state *ChoiceState, err error)

NewChoiceStateFromString NewChoiceStateFromString

func (*ChoiceState) ChoiceNextState

func (choice *ChoiceState) ChoiceNextState(input any) string

ChoiceNextState

func (*ChoiceState) GetBaseState

func (choice *ChoiceState) GetBaseState() *BaseState

func (*ChoiceState) GetBone

func (choice *ChoiceState) GetBone() StateBone

GetBone get choice bone

func (*ChoiceState) GetDefinition

func (choice *ChoiceState) GetDefinition() (string, error)

func (*ChoiceState) GetNextState

func (choice *ChoiceState) GetNextState(input any) (NextState, error)

GetNextState Get Next State input state origin input

func (*ChoiceState) IsEnd

func (choice *ChoiceState) IsEnd() bool

IsEnd check if choice is end, return false always, choice is not end state

type FailBody

type FailBody struct {
	Abort bool   `mapstructure:"Abort"`
	Cause string `mapstructure:"Cause"`
	Error string `mapstructure:"Error"`
}

func NewFailBodyFromMap

func NewFailBodyFromMap(data map[string]interface{}) (*FailBody, error)

type FailData

type FailData struct {
	Cause string `json:"cause"`
	Error string `json:"error"`
}

FailData Fail State Data

func (FailData) String

func (fd FailData) String() string

JSONString fail data string serialization

type FailState

type FailState struct {
	*BaseState `json:",inline"`
	*FailBody  `json:",inline"`
}

FailState 失败节点

func NewFailStateFromMap

func NewFailStateFromMap(data map[string]interface{}) (state *FailState, err error)

NewFailStateFromMap Create New Fail State

func NewFailStateFromString

func NewFailStateFromString(definition string) (state *FailState, err error)

NewFailStateFromString NewFailStateFromString

func (*FailState) GetBaseState

func (s *FailState) GetBaseState() *BaseState

func (*FailState) GetDefinition

func (s *FailState) GetDefinition() (string, error)

func (*FailState) GetFailData

func (s *FailState) GetFailData() FailData

GetFailData return fail state data

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 ...

func (*FieldError) Error

func (e *FieldError) Error() string

Error ...

type FiledPathError

type FiledPathError struct {
	// The error that occurred
	RawError error
	Paths    []string
}

FiledPathError FieldPathError is an error that occurred in a field at a specific path.

func (*FiledPathError) Error

func (e *FiledPathError) Error() string

Error ...

type NextState

type NextState struct {
	Name       string        // Next State Name
	Output     any           // 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 ParallelBody

type ParallelBody struct {
	Branches []map[string]interface{} `mapstructure:"Branches" validate:"required,gt=0"`
	// contains filtered or unexported fields
}

func NewParallelBodyFromMap

func NewParallelBodyFromMap(data map[string]interface{}, depth int) (*ParallelBody, error)

NewParallelBodyFromMap NewParallelBodyFromMap

type ParallelState

type ParallelState struct {
	*BaseState    `json:",inline"`
	*ParallelBody `json:",inline"`
	// contains filtered or unexported fields
}

ParallelState 并行状态

func NewParallelStateFromMap

func NewParallelStateFromMap(data map[string]interface{}, depth int) (*ParallelState, error)

NewParallelStateFromMap NewParallelStateFromMap

func NewParallelStateFromString

func NewParallelStateFromString(definition string, depth int) (*ParallelState, error)

NewParallelStateFromString NewParallelStateFromString

func (*ParallelState) GetBaseState

func (s *ParallelState) GetBaseState() *BaseState

func (*ParallelState) GetBranches

func (s *ParallelState) GetBranches() []*StateMachineBody

GetBranches 返回多个分支的statemachine

func (*ParallelState) GetDefinition

func (s *ParallelState) GetDefinition() (string, error)

func (*ParallelState) GetDepth

func (s *ParallelState) GetDepth() int

func (*ParallelState) SetDepth

func (s *ParallelState) SetDepth(depth int)

type PassBody

type PassBody struct {
	Result map[string]any `mapstructure:"Result" validate:"required"`
}

PassBody ...

func NewPassBodyFromMap

func NewPassBodyFromMap(data map[string]interface{}) (*PassBody, error)

func (*PassBody) GetOutput

func (p *PassBody) GetOutput(input any) (any, error)

type PassState

type PassState struct {
	*BaseState `json:",inline"`
	*PassBody  `json:",inline"`
}

PassState ...

func NewPassStateFromMap

func NewPassStateFromMap(data map[string]interface{}) (state *PassState, err error)

NewPassStateFromMap Create New Pass State From Map

func NewPassStateFromString

func NewPassStateFromString(definition string) (state *PassState, err error)

NewPassStateFromString Create New Pass State From String

func (*PassState) GetBaseState

func (p *PassState) GetBaseState() *BaseState

func (*PassState) GetDefinition

func (p *PassState) GetDefinition() (string, error)

func (*PassState) GetNextState

func (p *PassState) GetNextState(input any) (NextState, error)

GetNextState Get Next State

func (*PassState) GetResult

func (p *PassState) GetResult(input any) (any, error)

GetResult render result with input and parameters

type QueryLanguageType

type QueryLanguageType string

QueryLanguageType 查询语言类型

type ResourceURI

type ResourceURI struct {
	Resource     string
	ResourceType string
	Function     string
}

ResourceURI resource uri defintion

func ParseResource

func ParseResource(resource string) (uri *ResourceURI, err error)

ParseResource parser path to ResourceURI

type State

type State interface {
	Validate() error
	GetName() string
	SetName(name string)
	GetType() string
	GetBone() StateBone
	IsEnd() bool
	GetNext() []string
	GetBaseState() *BaseState
	GetDefinition() (string, error)
}

State ...

func NewStateFromMap

func NewStateFromMap(data map[string]interface{}, depth int) (state State, err error)

NewStateFromMap NewStateFromMap

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 ...

func NewStateMachineFromMap

func NewStateMachineFromMap(data map[string]interface{}) (*StateMachine, error)

func NewStateMachineFromString

func NewStateMachineFromString(data string) (*StateMachine, error)

func (StateMachine) GetBone

func (sm StateMachine) GetBone() StateMachineBone

GetBone GetBone

func (*StateMachine) GetGroupStates

func (sm *StateMachine) GetGroupStates() ([]StateMachineGroupState, error)

func (StateMachine) GetInput

func (sm StateMachine) GetInput(input any, executioninfo any) (any, error)

GetInput GetInput

func (*StateMachine) Init

func (sm *StateMachine) Init() (err error)

func (*StateMachine) Validate

func (s *StateMachine) Validate() string

Validate ...

type StateMachineBody

type StateMachineBody struct {
	StartAt string         `mapstructure:"StartAt" validate:"required,gt=0"`
	States  map[string]any `mapstructure:"States" validate:"required,gt=0"`
	// contains filtered or unexported fields
}

StateMachineBody statemachine 的body 定义

func NewDefaultStateMachineBody

func NewDefaultStateMachineBody(depth int) StateMachineBody

func NewStateMachineBodyFromMap

func NewStateMachineBodyFromMap(data map[string]any, depth int) (smb *StateMachineBody, err error)

NewStateMachineBodyFromMap Parse data to StateMachine

func NewStateMachineBodyFromString

func NewStateMachineBodyFromString(definition string, depth int) (smb *StateMachineBody, err error)

func (*StateMachineBody) AddState

func (smb *StateMachineBody) AddState(newstate State)

AddState 添加状态机中的状态

func (*StateMachineBody) GetBone

func (s *StateMachineBody) GetBone() StateMachineBone

func (*StateMachineBody) GetGroupStates

func (smb *StateMachineBody) GetGroupStates(startGroupID int) ([]StateMachineGroupState, error)

GetGroupStates 生成状态机中所有的state的group信息,并且拉平

func (*StateMachineBody) Init

func (smb *StateMachineBody) Init() (err error)

func (*StateMachineBody) SetNewStateFunc

func (smb *StateMachineBody) SetNewStateFunc(f func(data map[string]any, depth int) (State, error))

func (*StateMachineBody) SetStartAt

func (s *StateMachineBody) SetStartAt(name string)

func (*StateMachineBody) Validate

func (s *StateMachineBody) Validate() error

Validate ...

type StateMachineBone

type StateMachineBone struct {
	Version string               `json:"Version"`
	StartAt string               `json:"StartAt"`
	States  map[string]StateBone `json:"States"`
}

StateMachineBone StateMachineBone

type StateMachineGroupState

type StateMachineGroupState struct {
	GroupID    int            //自身的所处的group
	GroupIndex int            // 自身所在的GroupIndex
	Depth      int            //节点所在的 深度
	Name       string         // StateName
	State      State          //State
	SubGroup   *SubGroupState //子group列表
}

StateMachineGroupState statemachine

type StateMachineHeader

type StateMachineHeader struct {
	Version       string `json:"Version" mapstructure:"Version" ` // 语法版本, 默认1.0
	Type          string `json:"Type" mapstructure:"Type"`
	Comment       string `json:"Comment" mapstructure:"Comment"`
	QueryLanguage string `json:"QueryLanguage" mapstructure:"QueryLanguage"`
	// 任务执行超时时间, 过期自动设置任务状态为失败状态
	TimeoutSeconds int `json:"TimeoutSeconds" mapstructure:"TimeoutSeconds" validate:"gte=0"`
	// 任务执行超时终止时间,找过指定时间后,如果任务状态为非Success,任务自动终止并且设置为 Abort状态
	AbortTimeoutSeconds int `json:"AbortTimeoutSeconds" mapstructure:"AbortTimeoutSeconds" validate:"gte=0"`
	// Execution 的信息路径
	ExecutionInfoPath string `json:"ExecutionInfoPath" mapstructure:"ExecutionInfoPath"`
	// 默认input参数
	DefaultInput map[string]interface{} `json:"DefaultInput" mapstructure:"DefaultInput"`
	// contains filtered or unexported fields
}

StateMachineHeader statemachine的header 定义

func NewDefaultStateMachineHeader

func NewDefaultStateMachineHeader() StateMachineHeader

func NewStateMachineHeaderFromMap

func NewStateMachineHeaderFromMap(data map[string]interface{}) (*StateMachineHeader, error)

NewStateMachineHeaderFromMap NewStateMachineHeaderFromMap

func NewStateMachineHeaderFromString

func NewStateMachineHeaderFromString(definition string) (*StateMachineHeader, error)

NewStateMachineHeaderFromString NewStateMachineHeaderFromString

func (StateMachineHeader) GetDefinition

func (h StateMachineHeader) GetDefinition() string

GetDefinition returan header definition

func (StateMachineHeader) GetInput

func (h StateMachineHeader) GetInput(input interface{}, executioninfo interface{}) (interface{}, error)

GetInput 计算新的输入

func (StateMachineHeader) GetTimeout

func (h StateMachineHeader) GetTimeout() StateMachineTimeout

GetTimeout return statemachine timeout

func (*StateMachineHeader) Init

func (header *StateMachineHeader) Init() error

Init ...

type StateMachineTimeout

type StateMachineTimeout struct {
	Timeout      time.Duration
	TaskTimeout  time.Duration
	AbortTimeout time.Duration
}

StateMachineTimeout StateMachine 超时的结构

type StateType

type StateType string

StateType state type

type SubGroupState

type SubGroupState struct {
	MasterGroupID int
	MasterName    string
	SubGroupID    int    `json:"group_id"`
	SubStartAt    string `json:"start_at"`
}

SubGroupState statemachine中的子组

type SucceedState

type SucceedState struct {
	*BaseState `json:",inline"`
}

SucceedState 失败节点

func NewSucceedStateFromMap

func NewSucceedStateFromMap(data map[string]interface{}) (state *SucceedState, err error)

NewSucceedStateFromMap Create New Succeed State

func NewSucceedStateFromString

func NewSucceedStateFromString(definition string) (state *SucceedState, err error)

NewSucceedStateFromString NewSucceedStateFromString

func (*SucceedState) GetBaseState

func (s *SucceedState) GetBaseState() *BaseState

func (*SucceedState) GetDefinition

func (s *SucceedState) GetDefinition() (string, error)

func (*SucceedState) IsEnd

func (s *SucceedState) IsEnd() bool

IsEnd 是否是终止节点

type SuspendState

type SuspendState struct {
	*BaseState
}

SuspendState suspend state

func NewSuspendStateFromMap

func NewSuspendStateFromMap(data map[string]interface{}) (state *SuspendState, err error)

NewSucceedStateFromMap Create New Succeed State

func NewSuspendStateFromString

func NewSuspendStateFromString(definition string) (state *SuspendState, err error)

NewSuspendStateFromString NewSuspendStateFromString

func (*SuspendState) GetBaseState

func (s *SuspendState) GetBaseState() *BaseState

type TaskBody

type TaskBody struct {
	// Block : if block execution for task, default false
	// if true, the task will block the workflow execution until the manual call to resume the task
	// if false, the task will be executed automatically
	Block            bool   `mapstructure:"Block"`
	Resource         string `mapstructure:"Resource" validate:"required,gt=0"`
	TimeoutSeconds   uint   `mapstructure:"TimeoutSeconds" validate:"gte=0"`
	HeartbeatSeconds uint   `mapstructure:"HeartbeatSeconds" validate:"gte=0"`
	// Retry for decode
	Retry []TaskRetryNode `mapstructure:"Retry"`
	// Catch for decode
	Catch []TaskCatchNode `mapstructure:"Catch"`
}

TaskBody ...

func NewTaskBodyFromMap

func NewTaskBodyFromMap(data map[string]interface{}) (*TaskBody, error)

NewTaskBodyFromMap NewTaskBodyFromMap

func (*TaskBody) Init

func (body *TaskBody) Init() error

Init ...

func (*TaskBody) Validate

func (body *TaskBody) Validate() error

Validate ...

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 TaskState

type TaskState struct {
	*BaseState `json:",inline"`
	*TaskBody  `json:",inline"`
}

TaskState ...

func NewTaskStateFromMap

func NewTaskStateFromMap(data map[string]interface{}) (state *TaskState, err error)

NewTaskStateFromMap NewTaskStateFromMap

func NewTaskStateFromString

func NewTaskStateFromString(definition string) (state *TaskState, err error)

NewTaskStateFromString Create New Wait State

func (*TaskState) GetBaseState

func (t *TaskState) GetBaseState() *BaseState

func (*TaskState) GetBone

func (t *TaskState) GetBone() StateBone

GetBone get bone

func (*TaskState) GetDefinition

func (t *TaskState) GetDefinition() (string, error)

func (*TaskState) GetNextState

func (t *TaskState) GetNextState(input any, taskdata TaskSendData) (*NextState, error)

GetNextState get task next state @input state input data @taskdata task send data return next state

func (*TaskState) GetTaskTimeout

func (t *TaskState) GetTaskTimeout() (TaskTimeout, error)

GetTaskTimeout return task timeout

func (*TaskState) Init

func (t *TaskState) Init() error

Init init task

func (*TaskState) Validate

func (t *TaskState) Validate() error

Validate ...

type TaskTimeout

type TaskTimeout struct {
	TaskTimeout      time.Time
	HeartBeatTimeout time.Time
}

TaskTimeout Describe Task Timeout demand

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 ...

func NewWaitBodyFromMap

func NewWaitBodyFromMap(data map[string]interface{}) (state *WaitBody, err error)

func (*WaitBody) GetWakeupTime

func (w *WaitBody) GetWakeupTime(input any) (time.Time, error)

GetWakeupTime Get Wait State Wake up time

func (*WaitBody) Init

func (w *WaitBody) Init() error

type WaitState

type WaitState struct {
	*BaseState `json:",inline"`
	*WaitBody  `json:",inline"`
}

WaitState ...

func NewWaitStateFromMap

func NewWaitStateFromMap(data map[string]interface{}) (state *WaitState, err error)

NewWaitStateFromMap Create New Wait State

func NewWaitStateFromString

func NewWaitStateFromString(definition string) (state *WaitState, err error)

NewWaitStateFromString Create New Wait State

func (*WaitState) GetBaseState

func (w *WaitState) GetBaseState() *BaseState

func (*WaitState) GetDefinition

func (w *WaitState) GetDefinition() (string, error)

func (*WaitState) GetNextState

func (w *WaitState) GetNextState(input interface{}) (NextState, error)

GetNextState Get Next State

Jump to

Keyboard shortcuts

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