-
Notifications
You must be signed in to change notification settings - Fork 130
/
step.go
87 lines (76 loc) · 2.53 KB
/
step.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 dag
import (
"fmt"
"path"
"strings"
"time"
"github.com/dagu-dev/dagu/internal/utils"
)
// Step represents a step in a DAG.
type Step struct {
Name string `json:"Name"`
Description string `json:"Description,omitempty"`
Variables []string `json:"Variables,omitempty"`
OutputVariables *utils.SyncMap `json:"OutputVariables,omitempty"`
Dir string `json:"Dir,omitempty"`
ExecutorConfig ExecutorConfig `json:"ExecutorConfig,omitempty"`
CmdWithArgs string `json:"CmdWithArgs,omitempty"`
Command string `json:"Command,omitempty"`
Script string `json:"Script,omitempty"`
Stdout string `json:"Stdout,omitempty"`
Stderr string `json:"Stderr,omitempty"`
Output string `json:"Output,omitempty"`
Args []string `json:"Args,omitempty"`
Depends []string `json:"Depends,omitempty"`
ContinueOn ContinueOn `json:"ContinueOn,omitempty"`
RetryPolicy *RetryPolicy `json:"RetryPolicy,omitempty"`
RepeatPolicy RepeatPolicy `json:"RepeatPolicy,omitempty"`
MailOnError bool `json:"MailOnError,omitempty"`
Preconditions []*Condition `json:"Preconditions,omitempty"`
SignalOnStop string `json:"SignalOnStop,omitempty"`
SubWorkflow *SubWorkflow `json:"SubWorkflow,omitempty"`
}
type SubWorkflow struct {
Name string
Params string
}
// ExecutorConfig represents the configuration for the executor of a step.
type ExecutorConfig struct {
Type string
Config map[string]interface{}
}
const (
ExecutorTypeSubWorkflow = "subworkflow"
)
// RetryPolicy represents the retry policy for a step.
type RetryPolicy struct {
Limit int
Interval time.Duration
}
// RepeatPolicy represents the repeat policy for a step.
type RepeatPolicy struct {
Repeat bool
Interval time.Duration
}
// ContinueOn represents the conditions under which the step continues.
type ContinueOn struct {
Failure bool
Skipped bool
}
// String returns a string representation of the step's properties.
func (s *Step) String() string {
vals := []string{
fmt.Sprintf("Name: %s", s.Name),
fmt.Sprintf("Dir: %s", s.Dir),
fmt.Sprintf("Command: %s", s.Command),
fmt.Sprintf("Args: %s", s.Args),
fmt.Sprintf("Depends: [%s]", strings.Join(s.Depends, ", ")),
}
return strings.Join(vals, "\t")
}
// setup initializes the step's properties.
func (s *Step) setup(defaultLocation string) {
if s.Dir == "" {
s.Dir = path.Dir(defaultLocation)
}
}