-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_generic.go
63 lines (48 loc) · 1.29 KB
/
step_generic.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
package gsd
import "context"
// GenericStep is a generic Step implementation allowing users to provide
// arbitrary pre-exec/exec/post-exec/cleanup functions to be executed during
// the step's evaluation.
type GenericStep struct {
PreExecFunc func(context.Context, *State) error
ExecFunc func(context.Context, *State) error
PostExecFunc func(context.Context, *State) error
CleanupFunc func(context.Context, *State)
retries int
preExecOK bool
execOK bool
postExecOK bool
}
func (s *GenericStep) PreExec(ctx context.Context, state *State) error {
if s.PreExecFunc != nil && !s.preExecOK {
return s.PreExecFunc(ctx, state)
}
s.preExecOK = true
return nil
}
func (s *GenericStep) Exec(ctx context.Context, state *State) error {
if s.ExecFunc != nil && !s.execOK {
return s.ExecFunc(ctx, state)
}
s.execOK = true
return nil
}
func (s *GenericStep) PostExec(ctx context.Context, state *State) error {
if s.PostExecFunc != nil && !s.postExecOK {
return s.PostExecFunc(ctx, state)
}
s.postExecOK = true
return nil
}
func (s *GenericStep) Cleanup(ctx context.Context, state *State) {
if s.CleanupFunc != nil {
s.CleanupFunc(ctx, state)
}
}
func (s *GenericStep) Retries() int {
return s.retries
}
func (s *GenericStep) WithRetries(n int) Step {
s.retries = n
return s
}