process

package
v0.0.0-...-af92ede Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package process is the public API for execution engine of process. It contains a simple execution framework that can be used to implement a process engine.

Thre are 3 concepts in the package:

* Context: the container of variables and expressions.

* Flow: the process flow definition, mostly the container of nodes.

* State: the state of the process.

The definition of process flow is driven by states while nodes executes to change states and variables.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNotRunnable  = fmt.Errorf("not runnable")
	ErrNodeNotFound = fmt.Errorf("node not found")
)

predefined errors

Functions

func Complete

func Complete(inst Instance)

Complete complete the current execution.

func Continue

func Continue(inst Instance, fromNodeName string) error

Continue continue the flow by given node name.

func Run

func Run(inst Instance) error

Run a convenient method to execute the flow instance to a non-runnable state.

Example
package main

type SampleInstance struct {
	flow  Flow
	ctx   Context
	state State
}

func (i SampleInstance) GetContext() Context {
	return i.ctx
}

func (i SampleInstance) GetFlow() Flow {
	return i.flow
}

func (i SampleInstance) GetState() State {
	return i.state
}

func main() {
	var inst SampleInstance

	Continue(inst, "start")
	if err := Run(inst); err != nil {
		panic(err)
	}
}

func Step

func Step(inst Instance) error

Step step forward the process once a node.

func Terminate

func Terminate(inst Instance)

Terminate terminate the current execution by next node.

Types

type Context

type Context interface {
	Get(name string) Variable
	Eval(expr string) interface{}
}

Context the execution context interface.

type Flow

type Flow interface {
	GetName() string
	GetNode(name string) Node
}

Flow the flow definition interface.

type Instance

type Instance interface {
	GetContext() Context
	GetFlow() Flow
	GetState() State
}

Instance the execution instance.

type Node

type Node interface {
	GetName() string
	Execute(inst Instance) error
}

Node the execution node.

type State

type State interface {
	GetCurrentNode() string
	Name() StateName
	// contains filtered or unexported methods
}

State the state of the process.

func NewState

func NewState(name StateName, current string) State

NewState return the new state of the process.

type StateName

type StateName interface {
	// contains filtered or unexported methods
}

StateName the state name

var (
	StateNameRunnable   StateName = predefinedStateName("Runnable")
	StateNameRunning    StateName = predefinedStateName("Running")
	StateNamePending    StateName = predefinedStateName("Pending")
	StateNameCompleted  StateName = predefinedStateName("Completed")
	StateNameTerminated StateName = predefinedStateName("Terminated")
	StateNameError      StateName = predefinedStateName("Error")
)

State Names

type Variable

type Variable interface {
	GetName() string
	GetValue() interface{}
	SetValue(val interface{}) error
}

Variable the variable interface.

Jump to

Keyboard shortcuts

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