Skip to content

pipeline loop task clean result #3270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
11 changes: 11 additions & 0 deletions modules/pipeline/dbclient/op_pipeline_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,14 @@ func (client *Client) DeletePipelineTasksByPipelineID(pipelineID uint64, ops ...
return err
}, 3, time.Second)
}

func (client *Client) CleanPipelineTaskResult(id uint64, ops ...SessionOption) error {
session := client.NewSession(ops...)
defer session.Close()

if _, err := session.Table("pipeline_tasks").ID(id).
Update(map[string]interface{}{"result": nil}); err != nil {
return err
}
return nil
}
7 changes: 5 additions & 2 deletions modules/pipeline/pipengine/reconciler/taskrun/task_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ func (tr *TaskRun) resetTaskForLoop() {
tr.Task.Extra.TimeBeginQueue = time.Time{}
tr.Task.Extra.TimeEndQueue = time.Time{}
tr.Task.TimeEnd = time.Time{}
// reset task result
tr.Task.Result = nil
// reset volume
tr.Task.Context = spec.PipelineTaskContext{}
tr.Task.Extra.Volumes = nil
Expand All @@ -132,4 +130,9 @@ func (tr *TaskRun) resetTaskForLoop() {
tr.QuitWaitTimeout = false
tr.StopQueueLoop = false
tr.StopWaitLoop = false

// Now tr.update will not update the field whose value is nil,
// so need to call a separate method to clear the task whose result is loop type.
// It does not matter if the result is not cleared, but the result will retain an extra copy of the previous result.
tr.cleanTaskResult()
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func TestTaskRun_handleTaskLoop(t *testing.T) {
return map[string]string{}
})

var patch3 *monkey.PatchGuard
patch3 = monkey.PatchInstanceMethod(reflect.TypeOf(client), "CleanPipelineTaskResult", func(client *dbclient.Client, id uint64, ops ...dbclient.SessionOption) error {
return nil
})

var patch *monkey.PatchGuard
var tr = &TaskRun{}
if tt.fields.EnsureFetchLatestPipelineStatus != "" {
Expand All @@ -143,6 +148,7 @@ func TestTaskRun_handleTaskLoop(t *testing.T) {
}
patch1.Unpatch()
patch2.Unpatch()
patch3.Unpatch()
})
}
}
7 changes: 7 additions & 0 deletions modules/pipeline/pipengine/reconciler/taskrun/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ func (tr *TaskRun) EnsureFetchLatestPipelineStatus() {
})
tr.QueriedPipelineStatus = latestPStatus
}

func (tr *TaskRun) cleanTaskResult() {
tr.Task.Result = nil
if err := tr.DBClient.CleanPipelineTaskResult(tr.Task.ID); err != nil {
rlog.TWarnf(tr.P.ID, tr.Task.ID, "failed to clean task result, err: %v", err)
}
}