This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new cef7f773f fix(project): project cannot be deleted when its pipelines
are not finished (#8081)
cef7f773f is described below
commit cef7f773f3fa443925ca9461ccdd9f7f6d824868
Author: Lynwee <[email protected]>
AuthorDate: Fri Sep 20 11:45:08 2024 +0800
fix(project): project cannot be deleted when its pipelines are not finished
(#8081)
---
backend/core/models/task.go | 5 ++++-
backend/server/services/blueprint.go | 7 +++++++
backend/server/services/project.go | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/backend/core/models/task.go b/backend/core/models/task.go
index 661ba091a..34be9eff7 100644
--- a/backend/core/models/task.go
+++ b/backend/core/models/task.go
@@ -34,7 +34,10 @@ const (
TASK_PARTIAL = "TASK_PARTIAL"
)
-var PendingTaskStatus = []string{TASK_CREATED, TASK_RERUN, TASK_RUNNING}
+var (
+ PendingTaskStatus = []string{TASK_CREATED, TASK_RERUN, TASK_RUNNING}
+ FinishedTaskStatus = []string{TASK_PARTIAL, TASK_CANCELLED,
TASK_FAILED, TASK_COMPLETED}
+)
type TaskProgressDetail struct {
TotalSubTasks int `json:"totalSubTasks"`
diff --git a/backend/server/services/blueprint.go
b/backend/server/services/blueprint.go
index d400abae2..037149d0b 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -238,6 +238,13 @@ func DeleteBlueprint(id uint64) errors.Error {
if err != nil {
return err
}
+ pipelinesAreUnfinished, err :=
thereAreUnfinishedPipelinesUnderBlueprint(bp.ID)
+ if err != nil {
+ return err
+ }
+ if pipelinesAreUnfinished {
+ return errors.Default.New("There are unfinished pipelines under
current blueprint. It can not be deleted now.")
+ }
err = bpManager.DeleteBlueprint(bp.ID)
if err != nil {
return errors.Default.Wrap(err, "Failed to delete the
blueprint")
diff --git a/backend/server/services/project.go
b/backend/server/services/project.go
index 4739232ad..11ce1be78 100644
--- a/backend/server/services/project.go
+++ b/backend/server/services/project.go
@@ -20,6 +20,7 @@ package services
import (
"fmt"
"github.com/apache/incubator-devlake/helpers/pluginhelper/services"
+ "golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"strings"
"time"
@@ -322,6 +323,31 @@ func PatchProject(name string, body
map[string]interface{}) (*models.ApiOutputPr
return makeProjectOutput(project, false)
}
+func thereAreUnfinishedPipelinesUnderProject(projectName string) (bool,
errors.Error) {
+ blueprint, err := GetBlueprintByProjectName(projectName)
+ if err != nil {
+ return false, err
+ }
+ return thereAreUnfinishedPipelinesUnderBlueprint(blueprint.ID)
+}
+
+func thereAreUnfinishedPipelinesUnderBlueprint(blueprintID uint64) (bool,
errors.Error) {
+ // get the first page
+ dbPipelines, count, err := GetDbPipelines(&PipelineQuery{BlueprintId:
blueprintID})
+ if err != nil {
+ return false, err
+ }
+ if count <= 0 {
+ return false, nil
+ }
+ for _, pipeline := range dbPipelines {
+ if !slices.Contains(models.FinishedTaskStatus, pipeline.Status)
{
+ return true, nil
+ }
+ }
+ return false, nil
+}
+
// DeleteProject FIXME ...
func DeleteProject(name string) errors.Error {
// verify input
@@ -333,6 +359,14 @@ func DeleteProject(name string) errors.Error {
if err != nil {
return err
}
+ // make sure there is no running pipelines in current projects
+ pipelinesAreUnfinished, err :=
thereAreUnfinishedPipelinesUnderProject(name)
+ if err != nil {
+ return err
+ }
+ if pipelinesAreUnfinished {
+ return errors.Default.New("There are unfinished pipelines under
current project. It can not be deleted now.")
+ }
err = deleteProjectBlueprint(name)
if err != nil {
return err