Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add Tx suffix to TaskRun interface method since they are all used by Task inside a transaction
天舟2e549c166adc
diff --git a/api/task_run.go b/api/task_run.goindex 4d1d0e9e1d..715ee33153 100644--- a/api/task_run.go+++ b/api/task_run.go@@ -97,8 +97,8 @@ type TaskRunStatusPatch struct {}type TaskRunService interface {- CreateTaskRun(ctx context.Context, tx *sql.Tx, create *TaskRunCreate) (*TaskRun, error)- FindTaskRunList(ctx context.Context, tx *sql.Tx, find *TaskRunFind) ([]*TaskRun, error)- FindTaskRun(ctx context.Context, tx *sql.Tx, find *TaskRunFind) (*TaskRun, error)- PatchTaskRunStatus(ctx context.Context, tx *sql.Tx, patch *TaskRunStatusPatch) (*TaskRun, error)+ CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *TaskRunCreate) (*TaskRun, error)+ FindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) ([]*TaskRun, error)+ FindTaskRunTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) (*TaskRun, error)+ PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskRunStatusPatch) (*TaskRun, error)}diff --git a/store/task.go b/store/task.goindex b9a58eb66f..a1e135ec54 100644--- a/store/task.go+++ b/store/task.go@@ -272,7 +272,7 @@ func (s *TaskService) findTaskList(ctx context.Context, tx *Tx, find *api.TaskFitaskRunFind := &api.TaskRunFind{TaskId: &task.ID,}- task.TaskRunList, err = s.TaskRunService.FindTaskRunList(ctx, tx.Tx, taskRunFind)+ task.TaskRunList, err = s.TaskRunService.FindTaskRunListTx(ctx, tx.Tx, taskRunFind)if err != nil {return nil, err}@@ -305,7 +305,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Taapi.TaskRunRunning,},}- taskRun, err := s.TaskRunService.FindTaskRun(ctx, tx.Tx, taskRunFind)+ taskRun, err := s.TaskRunService.FindTaskRunTx(ctx, tx.Tx, taskRunFind)if err != nil {if common.ErrorCode(err) == common.ENOTFOUND {if patch.Status != api.TaskRunning {@@ -326,7 +326,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.TaType: task.Type,Payload: task.Payload,}- if _, err := s.TaskRunService.CreateTaskRun(ctx, tx.Tx, taskRunCreate); err != nil {+ if _, err := s.TaskRunService.CreateTaskRunTx(ctx, tx.Tx, taskRunCreate); err != nil {return nil, err}} else {@@ -345,7 +345,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Tacase api.TaskCanceled:taskRunStatusPatch.Status = api.TaskRunCanceled}- if _, err := s.TaskRunService.PatchTaskRunStatus(ctx, tx.Tx, taskRunStatusPatch); err != nil {+ if _, err := s.TaskRunService.PatchTaskRunStatusTx(ctx, tx.Tx, taskRunStatusPatch); err != nil {return nil, err}}@@ -394,7 +394,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.TataskRunFind := &api.TaskRunFind{TaskId: &task.ID,}- task.TaskRunList, err = s.TaskRunService.FindTaskRunList(ctx, tx.Tx, taskRunFind)+ task.TaskRunList, err = s.TaskRunService.FindTaskRunListTx(ctx, tx.Tx, taskRunFind)if err != nil {return nil, err}diff --git a/store/task_run.go b/store/task_run.goindex f8eed65d06..b56a2542c8 100644--- a/store/task_run.go+++ b/store/task_run.go@@ -26,8 +26,8 @@ func NewTaskRunService(logger *zap.Logger, db *DB) *TaskRunService {return &TaskRunService{l: logger, db: db}}-// CreateTaskRun creates a new taskRun.-func (s *TaskRunService) CreateTaskRun(ctx context.Context, tx *sql.Tx, create *api.TaskRunCreate) (*api.TaskRun, error) {+// CreateTaskRunTx creates a new taskRun.+func (s *TaskRunService) CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskRunCreate) (*api.TaskRun, error) {row, err := tx.QueryContext(ctx, `INSERT INTO task_run (creator_id,@@ -75,8 +75,8 @@ func (s *TaskRunService) CreateTaskRun(ctx context.Context, tx *sql.Tx, create *return &taskRun, nil}-// FindTaskRunList retrieves a list of taskRuns based on find.-func (s *TaskRunService) FindTaskRunList(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) ([]*api.TaskRun, error) {+// FindTaskRunListTx retrieves a list of taskRuns based on find.+func (s *TaskRunService) FindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) ([]*api.TaskRun, error) {list, err := s.findTaskRunList(ctx, tx, find)if err != nil {return []*api.TaskRun{}, err@@ -85,10 +85,10 @@ func (s *TaskRunService) FindTaskRunList(ctx context.Context, tx *sql.Tx, find *return list, nil}-// FindTaskRun retrieves a single taskRun based on find.+// FindTaskRunTx retrieves a single taskRun based on find.// Returns ENOTFOUND if no matching record.// Returns ECONFLICT if finding more than 1 matching records.-func (s *TaskRunService) FindTaskRun(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (*api.TaskRun, error) {+func (s *TaskRunService) FindTaskRunTx(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (*api.TaskRun, error) {list, err := s.findTaskRunList(ctx, tx, find)if err != nil {return nil, err@@ -100,8 +100,8 @@ func (s *TaskRunService) FindTaskRun(ctx context.Context, tx *sql.Tx, find *api.return list[0], nil}-// PatchTaskRunStatus updates a taskRun status. Returns the new state of the taskRun after update.-func (s *TaskRunService) PatchTaskRunStatus(ctx context.Context, tx *sql.Tx, patch *api.TaskRunStatusPatch) (*api.TaskRun, error) {+// PatchTaskRunStatusTx updates a taskRun status. Returns the new state of the taskRun after update.+func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *api.TaskRunStatusPatch) (*api.TaskRun, error) {// Build UPDATE clause.set, args := []string{}, []interface{}{}set, args = append(set, "`status` = ?"), append(args, patch.Status)