Skip to content

Commit

Permalink
fix: Propogate errors in task worker and don't return (#7357)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <simbeh7@gmail.com>
  • Loading branch information
simster7 authored Dec 8, 2021
1 parent 8bd7f39 commit 78dd747
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion workflow/executor/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ func (ae *AgentExecutor) taskWorker(ctx context.Context, taskQueue chan task, re
result, err := ae.processTask(ctx, tmpl)
if err != nil {
log.WithError(err).Error("Error in agent task")
return
result = &wfv1.NodeResult{
Phase: wfv1.NodeError,
Message: fmt.Sprintf("error processing task: %s", err),
}
// Do not return or continue here, the "errored" result still needs to be propagated to the responseQueue below
}

log.WithField("phase", result.Phase).
Expand Down
33 changes: 33 additions & 0 deletions workflow/executor/agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package executor

import (
"context"
"testing"

"github.com/stretchr/testify/assert"

"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)

func TestUnsupportedTemplateTaskWorker(t *testing.T) {
ae := &AgentExecutor{
consideredTasks: map[string]bool{},
}
taskQueue := make(chan task)
defer close(taskQueue)
responseQueue := make(chan response)
defer close(responseQueue)
go ae.taskWorker(context.Background(), taskQueue, responseQueue)

taskQueue <- task{
NodeId: "a",
// This template type is not supported
Template: v1alpha1.Template{
DAG: &v1alpha1.DAGTemplate{},
},
}

response := <-responseQueue
assert.Equal(t, v1alpha1.NodeError, response.Result.Phase)
assert.Contains(t, response.Result.Message, "agent cannot execute: unknown task type")
}

0 comments on commit 78dd747

Please sign in to comment.