Documentation
¶
Index ¶
- Constants
- func HandleCallback(ctx context.Context, req CallbackRequest, wf WorkflowState, s *State, ...) (interface{}, error)
- func HandleEvent(ctx context.Context, name string, wf WorkflowState, s *State, ...) (interface{}, error)
- func Resume(ctx context.Context, wf WorkflowState, s *State, save Checkpoint) error
- func Walk(s Stmt, f func(s Stmt) bool) (bool, error)
- type BreakStmt
- type CallbackRequest
- type Checkpoint
- type ForStmt
- type GoStmt
- type Handler
- type ResumeContext
- type ReturnStmt
- type Section
- type SelectStmt
- type State
- type Stmt
- type StmtStep
- type Stop
- type SwitchCase
- type SwitchStmt
- type Thread
- type ThreadStatus
- type Threads
- type WaitCond
- type WaitEvent
- type WaitEventStatus
- type WorkflowState
- type WorkflowStatus
Constants ¶
const MainThread = "_main_"
Variables ¶
This section is empty.
Functions ¶
func HandleCallback ¶ added in v0.9.0
func HandleCallback(ctx context.Context, req CallbackRequest, wf WorkflowState, s *State, input interface{}, save Checkpoint) (interface{}, error)
func HandleEvent ¶ added in v0.9.0
func HandleEvent(ctx context.Context, name string, wf WorkflowState, s *State, input interface{}, save Checkpoint) (interface{}, error)
HandleEvent is shortcut for calling HandleCallback() by event name. Be careful - if you have events with the same name waiting - you will not have control over which event will be called back. If this is important for you - you should use OnCallback() instead
func Resume ¶ added in v0.9.0
func Resume(ctx context.Context, wf WorkflowState, s *State, save Checkpoint) error
Resume the workflow after - workflow creation - successful callback handling - previously failed Resume() call
This method can be called multiple times. If there's nothing to resume - it will return 'nil'
Types ¶
type CallbackRequest ¶ added in v0.5.0
type Checkpoint ¶ added in v0.7.0
type GoStmt ¶ added in v0.5.0
type Handler ¶ added in v0.5.0
type Handler interface { Setup(ctx context.Context, req CallbackRequest) (json.RawMessage, error) Handle(ctx context.Context, req CallbackRequest, input interface{}) (interface{}, error) Teardown(ctx context.Context, req CallbackRequest) error }
func FindHandler ¶ added in v0.8.6
func FindHandler(req CallbackRequest, sec Stmt) (Handler, error)
type ResumeContext ¶ added in v0.5.0
type ResumeContext struct { // Running means process is already resumed and we are executing statements. // process is not running - we are searching for the step we should resume from. Running bool // In case workflow is resumed by a callback Callback CallbackRequest CallbackInput interface{} CallbackOutput interface{} Return bool Break bool // contains filtered or unexported fields }
ResumeContext is used during workflow execution It contains resume input as well as current state of the execution.
type ReturnStmt ¶ added in v0.5.0
type ReturnStmt struct { }
func (ReturnStmt) Resume ¶ added in v0.5.0
func (s ReturnStmt) Resume(ctx *ResumeContext) (*Stop, error)
type Section ¶ added in v0.5.0
type Section []Stmt
Section is similar to code block {} with a list of statements.
type SelectStmt ¶ added in v0.5.0
func Wait ¶ added in v0.5.0
func Wait(name string, ss ...WaitCond) SelectStmt
Wait for multiple conditions and execute only one
func (SelectStmt) Resume ¶ added in v0.5.0
func (s SelectStmt) Resume(ctx *ResumeContext) (*Stop, error)
type State ¶ added in v0.5.0
type State struct { ID string // id of workflow instance Workflow string // name of workflow definition. Used to choose proper state type to unmarshal & resume on Status WorkflowStatus // current status Threads Threads PC int }
type Stmt ¶ added in v0.5.0
type Stmt interface { // Resume continues execution of the process, based on ResumeContext // If ctx.Running == true Resume should execute the statement or continue execution after. // If ctx.Running = false Resume should not execute the statement, but recursively search for the statement that needs to be resumed. // If it needs to be resumed - don't execute it, but continue execution from this statement. // // If stmt not found *Stop will be nil and ctx.Running will be false // If stmt is found, but process has finished - *Stop will be nil and ctx.Running will be true // Otherwise Resume should always return *Stop or err != nil Resume(ctx *ResumeContext) (*Stop, error) }
Stmt is async statement definition that should support workflow resuming & search.
type Stop ¶ added in v0.5.0
type Stop struct { Step string // execute step Select *SelectStmt // wait for Events Return bool // stop this thread }
Stop tells us that syncronous part of the workflow has finished. It means we either:
type SwitchCase ¶ added in v0.5.0
func Case ¶
func Case(cond bool, sec Stmt) SwitchCase
func Default ¶ added in v0.5.0
func Default(sec Stmt) SwitchCase
type SwitchStmt ¶ added in v0.5.0
type SwitchStmt []SwitchCase
func If ¶ added in v0.5.0
func If(cond bool, sec Stmt) SwitchStmt
func Switch ¶ added in v0.5.0
func Switch(ss ...SwitchCase) SwitchStmt
execute statements based on condition
func (SwitchStmt) Resume ¶ added in v0.5.0
func (s SwitchStmt) Resume(ctx *ResumeContext) (*Stop, error)
type Thread ¶
type Thread struct { ID string Name string Status ThreadStatus // current status CurStep string // current step of the workflow WaitEvents []WaitEvent // events workflow is waiting for. Valid only if Status = Waiting, otherwise should be empty. PC int }
func (*Thread) WaitingForCallback ¶ added in v0.6.0
func (t *Thread) WaitingForCallback(cb CallbackRequest) error
type ThreadStatus ¶ added in v0.5.0
type ThreadStatus string
const ( ThreadExecuting ThreadStatus = "Executing" // next step for this thread is to execute "CurStep" step ThreadResuming ThreadStatus = "Resuming" // next step for this thread is to continue from "CurStep" step ThreadWaiting ThreadStatus = "Waiting" // thread is waiting for "CurStep" wait condition and will be resumed via OnCallback() )
type WaitCond ¶ added in v0.5.0
type WaitCond struct { Callback CallbackRequest Handler Handler Stmt Stmt }
type WaitEvent ¶ added in v0.5.0
type WaitEvent struct { Req CallbackRequest Status WaitEventStatus Error string }
type WaitEventStatus ¶ added in v0.6.0
type WaitEventStatus string
const ( EventPending WaitEventStatus = "Pending" // event is just created EventSetup WaitEventStatus = "Setup" // event was successfully setup EventSetupError WaitEventStatus = "SetupError" // there was an error during setup EventTeardownError WaitEventStatus = "TeardownError" // there was an error during teardown )
type WorkflowState ¶ added in v0.5.0
type WorkflowState interface { // Definition func may be called multiple times so it should be idempotent. // All actions should done in callbacks or steps. Definition() Section }
WorkflowState should be a Go struct supporting JSON unmarshalling into it. When process is resumed - current state is unmarshalled into it and then Definition() is called. This is needed to eliminate lasy parameters i.e. instead of 'If( func() bool { return s.IsAvailable})' we can write 'If(s.IsAvailable)'.
type WorkflowStatus ¶ added in v0.5.0
type WorkflowStatus string
const ( WorkflowRunning WorkflowStatus = "Running" WorkflowFinished WorkflowStatus = "Finished" )