Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go-sdk/pkg/worker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (w *worker) ExecuteTaskWorkload(ctx context.Context, workload api.ExecuteTa
var finalState api.TerminalTIState
body := &api.TIUpdateStatePayload{}

if taskContext.Err() == ErrTaskCancelledAfterFailedHeartbeat {
if errors.Is(context.Cause(taskContext), ErrTaskCancelledAfterFailedHeartbeat) {
// We've already logged when we failed to heartbeat, don't do it again
finalState = api.TerminalTIStateFailed
body.FromTITerminalStatePayload(api.TITerminalStatePayload{
Expand Down
34 changes: 34 additions & 0 deletions go-sdk/pkg/worker/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"log/slog"
"net/http"
"sync/atomic"
"testing"
"time"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"resty.dev/v3"

"github.com/apache/airflow/go-sdk/bundle/bundlev1"
"github.com/apache/airflow/go-sdk/pkg/api"
Expand Down Expand Up @@ -218,6 +220,38 @@ func (s *WorkerSuite) TestTaskHeartbeatsWhileRunning() {
True(count <= 11 && count >= 9, fmt.Sprintf("Call count of %d was not within the margin of error of 10+/-1", count))
}

func (s *WorkerSuite) TestTaskHeartbeatConflictStopsTask() {
id := uuid.New().String()
testWorkload := newTestWorkLoad(id, id[:8])

s.registry.AddDag(testWorkload.TI.DagId).
AddTaskWithName(testWorkload.TI.TaskId, func(ctx context.Context) error {
select {
case <-ctx.Done():
return nil
case <-time.After(2 * time.Second):
return fmt.Errorf("task context was not cancelled")
}
})

s.ExpectTaskRun(id)
s.ExpectTaskState(id, api.TerminalTIStateFailed)
s.ti.EXPECT().
Heartbeat(mock.Anything, uuid.MustParse(id), mock.Anything).
Return(&api.GeneralHTTPError{
Response: &resty.Response{
RawResponse: &http.Response{
Status: "409 Conflict",
StatusCode: http.StatusConflict,
},
},
})
s.client.EXPECT().TaskInstances().Return(s.ti)

err := s.worker.ExecuteTaskWorkload(context.Background(), testWorkload)
s.NoError(err)
}

func (s *WorkerSuite) TestTaskHeartbeatErrorStopsTaskAndLogs() {
s.T().Skip("TODO: Not implemented yet")
}
Expand Down