-
Notifications
You must be signed in to change notification settings - Fork 6
/
step_exec_options.go
55 lines (45 loc) · 1.6 KB
/
step_exec_options.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
package asyncjob
import (
"context"
"time"
)
type StepExecutionOptions struct {
ErrorPolicy StepErrorPolicy
RetryPolicy RetryPolicy
ContextPolicy StepContextPolicy
// dependencies that are not input.
DependOn []string
}
type StepErrorPolicy struct{}
type RetryPolicy interface {
// ShouldRetry returns true if the error should be retried, and the duration to wait before retrying.
// The int parameter is the retry count, first execution fail will invoke this with 0.
ShouldRetry(error, uint) (bool, time.Duration)
}
// StepContextPolicy allows context enrichment before passing to step.
//
// With StepInstanceMeta you can access StepInstance, StepDefinition, JobInstance, JobDefinition.
type StepContextPolicy func(context.Context, StepInstanceMeta) context.Context
type ExecutionOptionPreparer func(*StepExecutionOptions) *StepExecutionOptions
// Add precedence to a step.
//
// without taking input from it(use StepAfter/StepAfterBoth otherwise)
func ExecuteAfter(step StepDefinitionMeta) ExecutionOptionPreparer {
return func(options *StepExecutionOptions) *StepExecutionOptions {
options.DependOn = append(options.DependOn, step.GetName())
return options
}
}
// Allow retry of a step on error.
func WithRetry(retryPolicy RetryPolicy) ExecutionOptionPreparer {
return func(options *StepExecutionOptions) *StepExecutionOptions {
options.RetryPolicy = retryPolicy
return options
}
}
func WithContextEnrichment(contextPolicy StepContextPolicy) ExecutionOptionPreparer {
return func(options *StepExecutionOptions) *StepExecutionOptions {
options.ContextPolicy = contextPolicy
return options
}
}