Documentation
¶
Index ¶
- Constants
- type ActivatedJob
- type ActivityState
- type BpmnEngine
- type BpmnEngineError
- type BpmnEngineState
- func (state *BpmnEngineState) AddEventExporter(exporter exporter.EventExporter)
- func (state *BpmnEngineState) CreateAndRunInstance(processKey int64, variableContext map[string]interface{}) (*processInstanceInfo, error)
- func (state *BpmnEngineState) CreateAndRunInstanceById(processId string, variableContext map[string]interface{}) (*processInstanceInfo, error)
- func (state *BpmnEngineState) CreateInstance(processKey int64, variableContext map[string]interface{}) (*processInstanceInfo, error)
- func (state *BpmnEngineState) CreateInstanceById(processId string, variableContext map[string]interface{}) (*processInstanceInfo, error)
- func (state *BpmnEngineState) FindProcessInstance(processInstanceKey int64) *processInstanceInfo
- func (state *BpmnEngineState) FindProcessesById(id string) (infos []*ProcessInfo)
- func (state *BpmnEngineState) GetMessageSubscriptions() []MessageSubscription
- func (state *BpmnEngineState) GetTimersScheduled() []Timer
- func (state *BpmnEngineState) LoadFromBytes(xmlData []byte) (*ProcessInfo, error)
- func (state *BpmnEngineState) LoadFromFile(filename string) (*ProcessInfo, error)
- func (state *BpmnEngineState) Marshal() []byte
- func (state *BpmnEngineState) Name() string
- func (state *BpmnEngineState) NewTaskHandler() NewTaskHandlerCommand1
- func (state *BpmnEngineState) ProcessInstances() []*processInstanceInfo
- func (state *BpmnEngineState) PublishEventForInstance(processInstanceKey int64, messageName string, variables map[string]interface{}) error
- func (state *BpmnEngineState) RunOrContinueInstance(processInstanceKey int64) (*processInstanceInfo, error)
- type BpmnEngineUnmarshallingError
- type ExpressionEvaluationError
- type MessageSubscription
- func (m MessageSubscription) Element() *BPMN20.BaseElement
- func (m MessageSubscription) Key() int64
- func (m *MessageSubscription) MarshalJSON() ([]byte, error)
- func (m *MessageSubscription) SetState(state ActivityState)
- func (m MessageSubscription) State() ActivityState
- func (m *MessageSubscription) UnmarshalJSON(data []byte) error
- type NewTaskHandlerCommand1
- type NewTaskHandlerCommand2
- type ProcessInfo
- type ProcessInstance
- type ProcessInstanceInfoAlias
- type Timer
- type TimerState
- type VariableHolder
- func (vh *VariableHolder) GetVariable(key string) interface{}
- func (vh *VariableHolder) MarshalJSON() ([]byte, error)
- func (vh *VariableHolder) PropagateVariable(key string, value interface{})
- func (vh *VariableHolder) SetVariable(key string, val interface{})
- func (vh *VariableHolder) UnmarshalJSON(data []byte) error
- func (vh *VariableHolder) Variables() map[string]interface{}
Constants ¶
const CurrentSerializerVersion = 1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivatedJob ¶
type ActivatedJob interface {
// Key the key, a unique identifier for the job
Key() int64
// ProcessInstanceKey the job's process instance key
ProcessInstanceKey() int64
// BpmnProcessId Retrieve id of the job process definition
BpmnProcessId() string
// ProcessDefinitionVersion Retrieve version of the job process definition
ProcessDefinitionVersion() int32
// ProcessDefinitionKey Retrieve key of the job process definition
ProcessDefinitionKey() int64
// ElementId Get element id of the job
ElementId() string
// Variable from the process instance's variable context
Variable(key string) interface{}
// SetVariable in the variables context of the given process instance
SetVariable(key string, value interface{})
// InstanceKey get instance key from ProcessInfo
InstanceKey() int64
// CreatedAt when the job was created
CreatedAt() time.Time
// Fail does set the State the worker missed completing the job
// Fail and Complete mutual exclude each other
Fail(reason string)
// Complete does set the State the worker successfully completing the job
// Fail and Complete mutual exclude each other
Complete()
}
ActivatedJob represents an abstraction for the activated job don't forget to call Fail or Complete when your task worker job is complete or not.
type ActivityState ¶
type ActivityState string
ActivityState as per BPMN 2.0 spec, section 13.2.2 Activity, page 428, State diagram:
(Inactive)
O
|
A Token v
Arrives ┌─────┐
│Ready│
└─────┘
v Activity Interrupted An Alternative Path For
O -------------------------------------->O----------------------------+
Data InputSet v | Event Gateway Selected |
Available ┌──────┐ Interrupting| |
│Active│ Event | |
└──────┘ | v
v Activity Interrupted v An Alternative Path For┌─────────┐
O -------------------------------------->O ---------------------->│Withdrawn│
Activity's work v | Event Gateway Selected └─────────┘
completed ┌──────────┐ Interrupting| |
│Completing│ Event | The Process|
└──────────┘ | Ends |
v Activity Interrupted v Non-Error |
Completing O -------------------------------------->O--------------+ |
Requirements Done v Error v v |
Assignments ┌─────────┐ ┌───────┐ ┌───────────┐ |
Completed │Completed│ │Failing│ │Terminating│ |
└─────────┘ └───────┘ └───────────┘ |
v Compensation ┌────────────┐ v v |
O ------------->│Compensating│ O <-------------O Terminating |
| Occurs └────────────┘ v v Requirements Done
The Process | Compensation v Compensation | ┌──────────┐ |
Ends | +--------------O----------------/|\--------->│Terminated│ |
| | Completes | Interrupted | └──────────┘ |
| v | v | |
| ��───────────┐ |Compensation┌──────┐ | |
| │Compensated│ +----------->│Failed│ | |
| └─────┬─────┘ Failed └──────┘ | |
| | | | |
v / The Process Ends / Process Ends / |
O<--------------------------------------------------------------------+
(Closed)
const ( Active ActivityState = "ACTIVE" Compensated ActivityState = "COMPENSATED" Compensating ActivityState = "COMPENSATING" Completed ActivityState = "COMPLETED" Completing ActivityState = "COMPLETING" Failed ActivityState = "FAILED" Failing ActivityState = "FAILING" Ready ActivityState = "READY" Terminated ActivityState = "TERMINATED" Terminating ActivityState = "TERMINATING" Withdrawn ActivityState = "WITHDRAWN" )
type BpmnEngine ¶
type BpmnEngine interface {
LoadFromFile(filename string) (*ProcessInfo, error)
LoadFromBytes(xmlData []byte) (*ProcessInfo, error)
NewTaskHandler() NewTaskHandlerCommand1
CreateInstance(processKey int64, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateInstanceById(processId string, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateAndRunInstance(processKey int64, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateAndRunInstanceById(processId string, variableContext map[string]interface{}) (*processInstanceInfo, error)
RunOrContinueInstance(processInstanceKey int64) (*processInstanceInfo, error)
Name() string
ProcessInstances() []*processInstanceInfo
FindProcessInstance(processInstanceKey int64) *processInstanceInfo
FindProcessesById(id string) []*ProcessInfo
}
type BpmnEngineError ¶
type BpmnEngineError struct {
Msg string
}
func (*BpmnEngineError) Error ¶
func (e *BpmnEngineError) Error() string
type BpmnEngineState ¶
type BpmnEngineState struct {
// contains filtered or unexported fields
}
func NewWithName ¶
func NewWithName(name string) BpmnEngineState
NewWithName creates an engine with an arbitrary name of the engine; useful in case you have multiple ones, in order to distinguish them; also stored in when marshalling a process instance state, in case you want to store some special identifier
func Unmarshal ¶
func Unmarshal(data []byte) (BpmnEngineState, error)
Unmarshal loads the data byte array and creates a new instance of the BPMN Engine Will return an BpmnEngineUnmarshallingError, if there was an issue AND in case of error, the engine return object is only partially initialized and likely not usable
func (*BpmnEngineState) AddEventExporter ¶
func (state *BpmnEngineState) AddEventExporter(exporter exporter.EventExporter)
AddEventExporter registers an EventExporter instance
func (*BpmnEngineState) CreateAndRunInstance ¶
func (state *BpmnEngineState) CreateAndRunInstance(processKey int64, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateAndRunInstance creates a new instance and executes it immediately. The provided variableContext can be nil or refers to a variable map, which is provided to every service task handler function. Might return BpmnEngineError or ExpressionEvaluationError.
func (*BpmnEngineState) CreateAndRunInstanceById ¶
func (state *BpmnEngineState) CreateAndRunInstanceById(processId string, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateAndRunInstanceById creates a new instance by process ID (and uses latest process version), and executes it immediately. The provided variableContext can be nil or refers to a variable map, which is provided to every service task handler function. Might return BpmnEngineError or ExpressionEvaluationError.
func (*BpmnEngineState) CreateInstance ¶
func (state *BpmnEngineState) CreateInstance(processKey int64, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateInstance creates a new instance for a process with given processKey Might return BpmnEngineError, if process key was not found
func (*BpmnEngineState) CreateInstanceById ¶
func (state *BpmnEngineState) CreateInstanceById(processId string, variableContext map[string]interface{}) (*processInstanceInfo, error)
CreateInstanceById creates a new instance for a process with given process ID and uses latest version (if available) Might return BpmnEngineError, when no process with given ID was found
func (*BpmnEngineState) FindProcessInstance ¶
func (state *BpmnEngineState) FindProcessInstance(processInstanceKey int64) *processInstanceInfo
FindProcessInstance searches for a given processInstanceKey and returns the corresponding processInstanceInfo, or otherwise nil
func (*BpmnEngineState) FindProcessesById ¶
func (state *BpmnEngineState) FindProcessesById(id string) (infos []*ProcessInfo)
FindProcessesById returns all registered processes with given ID result array is ordered by version number, from 1 (first) and largest version (last)
func (*BpmnEngineState) GetMessageSubscriptions ¶
func (state *BpmnEngineState) GetMessageSubscriptions() []MessageSubscription
GetMessageSubscriptions the list of message subscriptions hint: each intermediate message catch event, will create such an active subscription, when a processes instance reaches such an element.
func (*BpmnEngineState) GetTimersScheduled ¶
func (state *BpmnEngineState) GetTimersScheduled() []Timer
GetTimersScheduled the list of all scheduled timers in the engine A Timer is created, when a process instance reaches a Timer Intermediate Catch Event element and expresses a timestamp in the future
func (*BpmnEngineState) LoadFromBytes ¶
func (state *BpmnEngineState) LoadFromBytes(xmlData []byte) (*ProcessInfo, error)
LoadFromBytes loads a given BPMN file by xmlData byte array into the engine and returns ProcessInfo details for the deployed workflow
func (*BpmnEngineState) LoadFromFile ¶
func (state *BpmnEngineState) LoadFromFile(filename string) (*ProcessInfo, error)
LoadFromFile loads a given BPMN file by filename into the engine and returns ProcessInfo details for the deployed workflow
func (*BpmnEngineState) Marshal ¶
func (state *BpmnEngineState) Marshal() []byte
func (*BpmnEngineState) Name ¶
func (state *BpmnEngineState) Name() string
Name returns the name of the engine, only useful in case you control multiple ones
func (*BpmnEngineState) NewTaskHandler ¶
func (state *BpmnEngineState) NewTaskHandler() NewTaskHandlerCommand1
NewTaskHandler registers a handler function to be called for service tasks with a given taskId
func (*BpmnEngineState) ProcessInstances ¶
func (state *BpmnEngineState) ProcessInstances() []*processInstanceInfo
ProcessInstances returns the list of process instances Hint: completed instances are prone to be removed from the list, which means typically you only see currently active process instances
func (*BpmnEngineState) PublishEventForInstance ¶
func (state *BpmnEngineState) PublishEventForInstance(processInstanceKey int64, messageName string, variables map[string]interface{}) error
PublishEventForInstance publishes a message with a given name and also adds variables to the process instance, which fetches this event
func (*BpmnEngineState) RunOrContinueInstance ¶
func (state *BpmnEngineState) RunOrContinueInstance(processInstanceKey int64) (*processInstanceInfo, error)
RunOrContinueInstance runs or continues a process instance by a given processInstanceKey. returns the process instances, when found; does nothing, if process is already in ProcessInstanceCompleted State; returns nil, nil when no process instance was found; might return BpmnEngineError or ExpressionEvaluationError.
type BpmnEngineUnmarshallingError ¶
func (*BpmnEngineUnmarshallingError) Error ¶
func (e *BpmnEngineUnmarshallingError) Error() string
type ExpressionEvaluationError ¶
func (*ExpressionEvaluationError) Error ¶
func (e *ExpressionEvaluationError) Error() string
type MessageSubscription ¶
type MessageSubscription struct {
ElementId string `json:"id"`
ElementInstanceKey int64 `json:"ik"`
ProcessKey int64 `json:"pk"`
ProcessInstanceKey int64 `json:"pik"`
Name string `json:"n"`
MessageState ActivityState `json:"s"`
CreatedAt time.Time `json:"c"`
// contains filtered or unexported fields
}
func (MessageSubscription) Element ¶
func (m MessageSubscription) Element() *BPMN20.BaseElement
func (MessageSubscription) Key ¶
func (m MessageSubscription) Key() int64
func (*MessageSubscription) MarshalJSON ¶
func (m *MessageSubscription) MarshalJSON() ([]byte, error)
func (*MessageSubscription) SetState ¶
func (m *MessageSubscription) SetState(state ActivityState)
func (MessageSubscription) State ¶
func (m MessageSubscription) State() ActivityState
func (*MessageSubscription) UnmarshalJSON ¶
func (m *MessageSubscription) UnmarshalJSON(data []byte) error
type NewTaskHandlerCommand1 ¶
type NewTaskHandlerCommand1 interface {
// Id defines a handler for a given element ID (as defined in the task element in the BPMN file)
// This is 1:1 relation between a handler and a task definition (since IDs are supposed to be unique).
Id(id string) NewTaskHandlerCommand2
// Type defines a handler for a Service Task with a given 'type';
// Hereby 'type' is defined as 'taskDefinition' extension element in the BPMN file.
// This allows a single handler to be used for multiple task definitions.
Type(taskType string) NewTaskHandlerCommand2
// Assignee defines a handler for a User Task with a given 'assignee';
// Hereby 'assignee' is defined as 'assignmentDefinition' extension element in the BPMN file.
Assignee(assignee string) NewTaskHandlerCommand2
// CandidateGroups defines a handler for a User Task with given 'candidate groups';
// For the handler you can specify one or more groups.
// If at least one matches a given user task, the handler will be called.
CandidateGroups(groups ...string) NewTaskHandlerCommand2
}
type NewTaskHandlerCommand2 ¶
type NewTaskHandlerCommand2 interface {
// Handler is the actual handler to be executed
Handler(func(job ActivatedJob))
}
type ProcessInfo ¶
type ProcessInfo struct {
BpmnProcessId string // The ID as defined in the BPMN file
Version int32 // A version of the process, default=1, incremented, when another process with the same ID is loaded
ProcessKey int64 // The engines key for this given process with version
// contains filtered or unexported fields
}
type ProcessInstance ¶
type ProcessInstance interface {
GetProcessInfo() *ProcessInfo
GetInstanceKey() int64
// GetVariable from the process instance's variable context
GetVariable(key string) interface{}
// SetVariable to the process instance's variable context
SetVariable(key string, value interface{})
GetCreatedAt() time.Time
GetState() ActivityState
}
type ProcessInstanceInfoAlias ¶
type ProcessInstanceInfoAlias processInstanceInfo // FIXME: don't export
type Timer ¶
type Timer struct {
ElementId string `json:"id"`
ElementInstanceKey int64 `json:"ik"`
ProcessKey int64 `json:"pk"`
ProcessInstanceKey int64 `json:"pik"`
TimerState TimerState `json:"s"`
CreatedAt time.Time `json:"c"`
DueAt time.Time `json:"da"`
Duration time.Duration `json:"du"`
// contains filtered or unexported fields
}
Timer is created, when a process instance reaches a Timer Intermediate Message Event. The logic is simple: CreatedAt + Duration = DueAt The TimerState is one of [ TimerCreated, TimerTriggered, TimerCancelled ]
func (Timer) Element ¶
func (t Timer) Element() *BPMN20.BaseElement
func (*Timer) MarshalJSON ¶
func (*Timer) SetState ¶
func (t *Timer) SetState(state ActivityState)
func (Timer) State ¶
func (t Timer) State() ActivityState
func (*Timer) UnmarshalJSON ¶
type TimerState ¶
type TimerState string
const TimerCancelled TimerState = "CANCELLED"
const TimerCreated TimerState = "CREATED"
const TimerTriggered TimerState = "TRIGGERED"
type VariableHolder ¶
type VariableHolder struct {
// contains filtered or unexported fields
}
func NewVarHolder ¶
func NewVarHolder(parent *VariableHolder, variables map[string]interface{}) VariableHolder
NewVarHolder creates a new VariableHolder with a given parent and variables map. All variables from parent holder are copied into this one. (hint: the copy is necessary, due to the fact we need to have all variables for expression evaluation in one map)
func (*VariableHolder) GetVariable ¶
func (vh *VariableHolder) GetVariable(key string) interface{}
func (*VariableHolder) MarshalJSON ¶
func (vh *VariableHolder) MarshalJSON() ([]byte, error)
func (*VariableHolder) PropagateVariable ¶
func (vh *VariableHolder) PropagateVariable(key string, value interface{})
PropagateVariable set a value with given key to the parent VariableHolder
func (*VariableHolder) SetVariable ¶
func (vh *VariableHolder) SetVariable(key string, val interface{})
func (*VariableHolder) UnmarshalJSON ¶
func (vh *VariableHolder) UnmarshalJSON(data []byte) error
func (*VariableHolder) Variables ¶
func (vh *VariableHolder) Variables() map[string]interface{}
Variables return all variables within this holder