This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
execution_context.go
117 lines (95 loc) · 3.1 KB
/
execution_context.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package executors
import (
"github.com/flyteorg/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
)
type TaskDetailsGetter interface {
GetTask(id v1alpha1.TaskID) (v1alpha1.ExecutableTask, error)
}
type SubWorkflowGetter interface {
FindSubWorkflow(subID v1alpha1.WorkflowID) v1alpha1.ExecutableSubWorkflow
}
type ImmutableExecutionContext interface {
v1alpha1.Meta
GetID() v1alpha1.WorkflowID
GetOnFailurePolicy() v1alpha1.WorkflowOnFailurePolicy
GetExecutionConfig() v1alpha1.ExecutionConfig
}
type ParentInfoGetter interface {
GetParentInfo() ImmutableParentInfo
}
type ImmutableParentInfo interface {
GetUniqueID() v1alpha1.NodeID
CurrentAttempt() uint32
}
type ControlFlow interface {
CurrentParallelism() uint32
IncrementParallelism() uint32
}
type ExecutionContext interface {
ImmutableExecutionContext
TaskDetailsGetter
SubWorkflowGetter
ParentInfoGetter
ControlFlow
}
type execContext struct {
ControlFlow
ImmutableExecutionContext
TaskDetailsGetter
SubWorkflowGetter
parentInfo ImmutableParentInfo
}
func (e execContext) GetParentInfo() ImmutableParentInfo {
return e.parentInfo
}
type parentExecutionInfo struct {
uniqueID v1alpha1.NodeID
currentAttempts uint32
}
func (p *parentExecutionInfo) GetUniqueID() v1alpha1.NodeID {
return p.uniqueID
}
func (p *parentExecutionInfo) CurrentAttempt() uint32 {
return p.currentAttempts
}
type controlFlow struct {
// We could use atomic.Uint32, but this is not required for current Propeller. As every round is run in a single
// thread and using atomic will introduce memory barriers
v uint32
}
func (c *controlFlow) CurrentParallelism() uint32 {
return c.v
}
func (c *controlFlow) IncrementParallelism() uint32 {
c.v = c.v + 1
return c.v
}
func NewExecutionContextWithTasksGetter(prevExecContext ExecutionContext, taskGetter TaskDetailsGetter) ExecutionContext {
return NewExecutionContext(prevExecContext, taskGetter, prevExecContext, prevExecContext.GetParentInfo(), prevExecContext)
}
func NewExecutionContextWithWorkflowGetter(prevExecContext ExecutionContext, getter SubWorkflowGetter) ExecutionContext {
return NewExecutionContext(prevExecContext, prevExecContext, getter, prevExecContext.GetParentInfo(), prevExecContext)
}
func NewExecutionContextWithParentInfo(prevExecContext ExecutionContext, parentInfo ImmutableParentInfo) ExecutionContext {
return NewExecutionContext(prevExecContext, prevExecContext, prevExecContext, parentInfo, prevExecContext)
}
func NewExecutionContext(immExecContext ImmutableExecutionContext, tasksGetter TaskDetailsGetter, workflowGetter SubWorkflowGetter, parentInfo ImmutableParentInfo, flow ControlFlow) ExecutionContext {
return execContext{
ImmutableExecutionContext: immExecContext,
TaskDetailsGetter: tasksGetter,
SubWorkflowGetter: workflowGetter,
parentInfo: parentInfo,
ControlFlow: flow,
}
}
func NewParentInfo(uniqueID string, currentAttempts uint32) ImmutableParentInfo {
return &parentExecutionInfo{
currentAttempts: currentAttempts,
uniqueID: uniqueID,
}
}
func InitializeControlFlow() ControlFlow {
return &controlFlow{
v: 0,
}
}