You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/09/20 03:51:54 UTC

(incubator-devlake) branch cp10 created (now 89eb66c6c)

This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a change to branch cp10
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


      at 89eb66c6c fix(project): project cannot be deleted when its pipelines are not finished

This branch includes the following new commits:

     new 89eb66c6c fix(project): project cannot be deleted when its pipelines are not finished

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(incubator-devlake) 01/01: fix(project): project cannot be deleted when its pipelines are not finished

Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch cp10
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 89eb66c6c9c583ba22e300afc45cfc475606208b
Author: d4x1 <15...@qq.com>
AuthorDate: Fri Sep 20 11:35:20 2024 +0800

    fix(project): project cannot be deleted when its pipelines are not finished
---
 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 8e9528d38..8ef169781 100644
--- a/backend/server/services/project.go
+++ b/backend/server/services/project.go
@@ -19,6 +19,7 @@ package services
 
 import (
 	"fmt"
+	"golang.org/x/exp/slices"
 	"golang.org/x/sync/errgroup"
 	"strings"
 	"time"
@@ -321,6 +322,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
@@ -332,6 +358,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