Skip to content

Commit

Permalink
Fix: fix suspend judgement (#196)
Browse files Browse the repository at this point in the history
Fix: fix context in provider (#194)

fix: fix context in provider

Signed-off-by: FogDong <[email protected]>
  • Loading branch information
FogDong authored Sep 24, 2024
1 parent 76db4ac commit 55f1433
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
17 changes: 9 additions & 8 deletions pkg/executor/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
}
return v1alpha1.WorkflowStateFailed, nil
}
if checkWorkflowSuspended(status) {
return v1alpha1.WorkflowStateSuspending, nil
}
if allRunnersSucceeded {
return v1alpha1.WorkflowStateSucceeded, nil
}

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

if checkWorkflowSuspended(status) {
return v1alpha1.WorkflowStateSuspending, nil
}
if allRunnersSucceeded {
return v1alpha1.WorkflowStateSucceeded, nil
}

if cacheValue, ok := StepStatusCache.Load(cacheKey); ok {
// handle cache resource
if len(status.Steps) < cacheValue.(int) {
Expand Down Expand Up @@ -173,11 +174,11 @@ func checkWorkflowSuspended(status *v1alpha1.WorkflowRunStatus) bool {
// if workflow is suspended and the suspended step is still running, return false to run the suspended step
if status.Suspend {
for _, step := range status.Steps {
if step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
if step.Reason == types.StatusReasonSuspend && step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
return false
}
for _, sub := range step.SubStepsStatus {
if sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
if sub.Reason == types.StatusReasonSuspend && sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
return false
}
}
Expand Down
36 changes: 20 additions & 16 deletions pkg/executor/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1772,10 +1772,11 @@ var _ = Describe("Test Workflow", func() {
},
}, {
StepStatus: v1alpha1.StepStatus{
Name: "s2",
ID: "s2",
Type: "suspend",
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Name: "s2",
ID: "s2",
Type: "suspend",
Reason: types.StatusReasonSuspend,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
},
}},
})).Should(BeEquivalentTo(""))
Expand Down Expand Up @@ -1805,10 +1806,11 @@ var _ = Describe("Test Workflow", func() {
},
}, {
StepStatus: v1alpha1.StepStatus{
Name: "s2",
ID: "s2",
Type: "suspend",
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
Name: "s2",
ID: "s2",
Type: "suspend",
Reason: types.StatusReasonSuspend,
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
},
}, {
StepStatus: v1alpha1.StepStatus{
Expand Down Expand Up @@ -1884,10 +1886,11 @@ var _ = Describe("Test Workflow", func() {
Type: "success",
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
}, {
Name: "s2-sub2",
ID: "s2-sub2",
Type: "suspend",
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Name: "s2-sub2",
ID: "s2-sub2",
Type: "suspend",
Reason: types.StatusReasonSuspend,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
},
},
}},
Expand Down Expand Up @@ -2234,10 +2237,11 @@ func makeRunner(step v1alpha1.WorkflowStep, subTaskRunners []types.TaskRunner) t
}
}
return v1alpha1.StepStatus{
Name: step.Name,
Type: "suspend",
ID: step.Name,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Name: step.Name,
Type: "suspend",
ID: step.Name,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Reason: types.StatusReasonSuspend,
}, &types.Operation{
Suspend: true,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/custom/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (exec *executor) Terminate(message string) {
// Wait let workflow wait.
func (exec *executor) Wait(message string) {
exec.wait = true
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed {
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed && exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseSuspending {
exec.wfStatus.Phase = v1alpha1.WorkflowStepPhaseRunning
exec.wfStatus.Reason = types.StatusReasonWait
if message != "" {
Expand Down

0 comments on commit 55f1433

Please sign in to comment.