forked from viant/endly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.go
50 lines (45 loc) · 967 Bytes
/
workflow.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
package model
import (
"github.com/pkg/errors"
"github.com/viant/toolbox/data"
"github.com/viant/toolbox/url"
)
//Workflow repesents a workflow
type Workflow struct {
Source *url.Resource //source definition of the workflow
Data data.Map //workflow data
*AbstractNode
*TasksNode //workflow task
}
//Validate validates this workflow
func (w *Workflow) Init() error {
for _, task := range w.Tasks {
if len(task.Actions) == 0 {
task.Actions = []*Action{}
continue
}
for _, action := range task.Actions {
if err := action.Init(); err != nil {
return err
}
}
}
return nil
}
//Validate validates this workflow
func (w *Workflow) Validate() error {
if len(w.Tasks) == 0 {
return errors.New("tasks were empty")
}
if w.DeferredTask != "" {
if _, err := w.Task(w.DeferredTask); err != nil {
return err
}
}
if w.OnErrorTask != "" {
if _, err := w.Task(w.OnErrorTask); err != nil {
return err
}
}
return nil
}