-
Notifications
You must be signed in to change notification settings - Fork 78
/
flowbehavior.go
67 lines (48 loc) · 1.77 KB
/
flowbehavior.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
package simple
import (
"github.com/TIBCOSoftware/flogo-contrib/action/flow/definition"
"github.com/TIBCOSoftware/flogo-contrib/action/flow/model"
)
// FlowBehavior implements model.FlowBehavior
type FlowBehavior struct {
}
// Start implements model.FlowBehavior.Start
func (fb *FlowBehavior) Start(ctx model.FlowContext) (started bool, taskEntries []*model.TaskEntry) {
return true, getFlowTaskEntries(ctx.FlowDefinition().Tasks(), true)
}
// StartErrorHandler implements model.FlowBehavior.StartErrorHandler
func (fb *FlowBehavior) StartErrorHandler(ctx model.FlowContext) (taskEntries []*model.TaskEntry) {
return getFlowTaskEntries(ctx.FlowDefinition().GetErrorHandler().Tasks(), true)
}
// Resume implements model.FlowBehavior.Resume
func (fb *FlowBehavior) Resume(ctx model.FlowContext) (resumed bool) {
return true
}
// TasksDone implements model.FlowBehavior.TasksDone
func (fb *FlowBehavior) TaskDone(ctx model.FlowContext) (flowDone bool) {
tasks := ctx.TaskInstances()
log.Debug("Checking if all tasks done or skipped")
for _, taskInst := range tasks {
if taskInst.Status() < model.TaskStatusDone { //ignore not started?
log.Debugf("Task '%s' not done or skipped", taskInst.Task().ID())
return false
}
}
log.Debug("All tasks done or skipped")
// our tasks are done, so the flow is done
return true
}
// Done implements model.FlowBehavior.Done
func (fb *FlowBehavior) Done(ctx model.FlowContext) {
log.Debugf("Flow Done")
}
func getFlowTaskEntries(tasks []*definition.Task, leadingOnly bool) []*model.TaskEntry {
var taskEntries []*model.TaskEntry
for _, task := range tasks {
if len(task.FromLinks()) == 0 || !leadingOnly {
taskEntry := &model.TaskEntry{Task: task, EnterCode: 0}
taskEntries = append(taskEntries, taskEntry)
}
}
return taskEntries
}