Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: refine BatchRunTasks (#7407)

p0nyc62b89ecfeee
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index b34203587e..0e70284fdd 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -4,12 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
- "net/http"
"strconv"
"strings"
"time"
- "github.com/labstack/echo/v4"
"github.com/pkg/errors"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
@@ -443,12 +441,12 @@ func (s *RolloutService) BatchRunTasks(ctx context.Context, request *v1pb.BatchR
stageToRun = stage
break
}
- if stage.Active {
- return nil, status.Errorf(codes.InvalidArgument, "Tasks in a prior stage are not done yet")
- }
}
break
}
+ if stageToRun == nil {
+ return nil, status.Errorf(codes.Internal, "failed to find the stage to run")
+ }
pendingApprovalStatus := []api.TaskStatus{api.TaskPendingApproval}
stageToRunTasks, err := s.store.ListTasks(ctx, &api.TaskFind{PipelineID: &rolloutID, StageID: &stageToRun.ID, StatusList: &pendingApprovalStatus})
@@ -478,10 +476,10 @@ func (s *RolloutService) BatchRunTasks(ctx context.Context, request *v1pb.BatchR
approved, err := utils.CheckIssueApproved(issue)
if err != nil {
- return nil, echo.NewHTTPError(http.StatusInternalServerError, "Failed to check if the issue is approved").SetInternal(err)
+ return nil, status.Errorf(codes.Internal, "failed to check if the issue is approved, error: %v", err)
}
if !approved {
- return nil, echo.NewHTTPError(http.StatusBadRequest, "Cannot patch task status because the issue is not approved")
+ return nil, status.Errorf(codes.FailedPrecondition, "cannot run the tasks because the issue is not approved")
}
var taskRunCreates []*store.TaskRunMessage
diff --git a/backend/store/task_run.go b/backend/store/task_run.go
index 62aa43bbd4..a83d3bdd9a 100644
--- a/backend/store/task_run.go
+++ b/backend/store/task_run.go
@@ -221,7 +221,7 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creates ...*TaskRunMe
taskIDs = append(taskIDs, create.TaskUID)
}
- exist, err := s.checkTaskRunsExist(ctx, tx, taskIDs, []api.TaskRunStatus{api.TaskRunPending, api.TaskRunRunning})
+ exist, err := s.checkTaskRunsExist(ctx, tx, taskIDs, []api.TaskRunStatus{api.TaskRunPending, api.TaskRunRunning, api.TaskRunDone})
if err != nil {
return errors.Wrapf(err, "failed to check if task runs exist")
}