forked from TIBCOSoftware/flogo-contrib
/
behavior.go
87 lines (68 loc) · 2.84 KB
/
behavior.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package model
import (
"github.com/TIBCOSoftware/flogo-contrib/action/flow/definition"
)
// TaskEntry is a struct used to specify what Task to
// enter and its corresponding enter code
type TaskEntry struct {
Task *definition.Task
EnterCode int
}
// FlowBehavior is the execution behavior of the Flow.
type FlowBehavior interface {
// Start the flow instance. Returning true indicates that the
// flow can start and enter the specified tasks.
// Return false indicates that the flow could not be started
// at this time.
Start(context FlowContext) (started bool, taskEntries []*TaskEntry)
// StartErrorHandler start the error handler for the flow.
// Return the list of tasks to start
StartErrorHandler(context FlowContext) (taskEntries []*TaskEntry)
// Resume the flow instance. Returning true indicates that the
// flow can resume. Return false indicates that the flow
// could not be resumed at this time.
Resume(context FlowContext) (resumed bool)
// TasksDone is called when a terminal task is Done.
TaskDone(context FlowContext) (flowDone bool)
// Done is called when the flow is done.
Done(context FlowContext)
}
type EvalResult int
const (
EVAL_FAIL EvalResult = iota
EVAL_DONE
EVAL_REPEAT
EVAL_WAIT
EVAL_SKIP
)
type EnterResult int
const (
ENTER_NOTREADY EnterResult = iota
ENTER_EVAL
ENTER_SKIP
)
// TaskBehavior is the execution behavior of a Task.
type TaskBehavior interface {
// Enter determines if a Task is ready to be evaluated, or needs to be
// skipped
Enter(context TaskContext) (enterResult EnterResult)
// Eval is called when a Task is being evaluated. Returning true indicates
// that the task is done. If err is set, it indicates that the
// behavior intends for the flow ErrorHandler to handle the error
Eval(context TaskContext) (evalResult EvalResult, err error)
// PostEval is called when a task that is waiting needs to be notified.
// If err is set, it indicates that the behavior intends for the
// flow ErrorHandler to handle the error
PostEval(context TaskContext) (evalResult EvalResult, err error)
// Done is called when Eval or PostEval return a result of DONE, indicating
// that the task is done. This step is used to finalize the task and
// determine the next set of tasks to be entered.
Done(context TaskContext) (notifyFlow bool, taskEntries []*TaskEntry, err error)
// Skip is called when Enter returns a result of SKIP, indicating
// that the task should be skipped. This step is used to skip the task and
// determine the next set of tasks to be entered.
Skip(context TaskContext) (notifyFlow bool, taskEntries []*TaskEntry)
// Error is called when there is an issue executing Eval, it returns a boolean indicating
// if it handled the error, otherwise the error is handled by the global error handler
Error(context TaskContext, err error) (handled bool, taskEntries []*TaskEntry)
}