Skip to content

Commit 55f1433

Browse files
authored
Fix: fix suspend judgement (#196)
Fix: fix context in provider (#194) fix: fix context in provider Signed-off-by: FogDong <[email protected]>
1 parent 76db4ac commit 55f1433

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

pkg/executor/workflow.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
113113
}
114114
return v1alpha1.WorkflowStateFailed, nil
115115
}
116-
if checkWorkflowSuspended(status) {
117-
return v1alpha1.WorkflowStateSuspending, nil
118-
}
119-
if allRunnersSucceeded {
120-
return v1alpha1.WorkflowStateSucceeded, nil
121-
}
122116

123117
wfCtx, err := w.makeContext(ctx, w.instance.Name)
124118
if err != nil {
@@ -127,6 +121,13 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
127121
}
128122
w.wfCtx = wfCtx
129123

124+
if checkWorkflowSuspended(status) {
125+
return v1alpha1.WorkflowStateSuspending, nil
126+
}
127+
if allRunnersSucceeded {
128+
return v1alpha1.WorkflowStateSucceeded, nil
129+
}
130+
130131
if cacheValue, ok := StepStatusCache.Load(cacheKey); ok {
131132
// handle cache resource
132133
if len(status.Steps) < cacheValue.(int) {
@@ -173,11 +174,11 @@ func checkWorkflowSuspended(status *v1alpha1.WorkflowRunStatus) bool {
173174
// if workflow is suspended and the suspended step is still running, return false to run the suspended step
174175
if status.Suspend {
175176
for _, step := range status.Steps {
176-
if step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
177+
if step.Reason == types.StatusReasonSuspend && step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
177178
return false
178179
}
179180
for _, sub := range step.SubStepsStatus {
180-
if sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
181+
if sub.Reason == types.StatusReasonSuspend && sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
181182
return false
182183
}
183184
}

pkg/executor/workflow_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,10 +1772,11 @@ var _ = Describe("Test Workflow", func() {
17721772
},
17731773
}, {
17741774
StepStatus: v1alpha1.StepStatus{
1775-
Name: "s2",
1776-
ID: "s2",
1777-
Type: "suspend",
1778-
Phase: v1alpha1.WorkflowStepPhaseSuspending,
1775+
Name: "s2",
1776+
ID: "s2",
1777+
Type: "suspend",
1778+
Reason: types.StatusReasonSuspend,
1779+
Phase: v1alpha1.WorkflowStepPhaseSuspending,
17791780
},
17801781
}},
17811782
})).Should(BeEquivalentTo(""))
@@ -1805,10 +1806,11 @@ var _ = Describe("Test Workflow", func() {
18051806
},
18061807
}, {
18071808
StepStatus: v1alpha1.StepStatus{
1808-
Name: "s2",
1809-
ID: "s2",
1810-
Type: "suspend",
1811-
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
1809+
Name: "s2",
1810+
ID: "s2",
1811+
Type: "suspend",
1812+
Reason: types.StatusReasonSuspend,
1813+
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
18121814
},
18131815
}, {
18141816
StepStatus: v1alpha1.StepStatus{
@@ -1884,10 +1886,11 @@ var _ = Describe("Test Workflow", func() {
18841886
Type: "success",
18851887
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
18861888
}, {
1887-
Name: "s2-sub2",
1888-
ID: "s2-sub2",
1889-
Type: "suspend",
1890-
Phase: v1alpha1.WorkflowStepPhaseSuspending,
1889+
Name: "s2-sub2",
1890+
ID: "s2-sub2",
1891+
Type: "suspend",
1892+
Reason: types.StatusReasonSuspend,
1893+
Phase: v1alpha1.WorkflowStepPhaseSuspending,
18911894
},
18921895
},
18931896
}},
@@ -2234,10 +2237,11 @@ func makeRunner(step v1alpha1.WorkflowStep, subTaskRunners []types.TaskRunner) t
22342237
}
22352238
}
22362239
return v1alpha1.StepStatus{
2237-
Name: step.Name,
2238-
Type: "suspend",
2239-
ID: step.Name,
2240-
Phase: v1alpha1.WorkflowStepPhaseSuspending,
2240+
Name: step.Name,
2241+
Type: "suspend",
2242+
ID: step.Name,
2243+
Phase: v1alpha1.WorkflowStepPhaseSuspending,
2244+
Reason: types.StatusReasonSuspend,
22412245
}, &types.Operation{
22422246
Suspend: true,
22432247
}, nil

pkg/tasks/custom/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (exec *executor) Terminate(message string) {
8585
// Wait let workflow wait.
8686
func (exec *executor) Wait(message string) {
8787
exec.wait = true
88-
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed {
88+
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed && exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseSuspending {
8989
exec.wfStatus.Phase = v1alpha1.WorkflowStepPhaseRunning
9090
exec.wfStatus.Reason = types.StatusReasonWait
9191
if message != "" {

0 commit comments

Comments
 (0)