Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -498,38 +498,6 @@ func (c *WorkflowV4Coll) ListByCursor(opt *ListWorkflowV4Option) (*mongo.Cursor,
return c.Collection.Find(context.TODO(), query)
}

// ListNamesByAITarget returns the display names of the workflows that reference the
// given AI target in an AI job, so that the target is not deleted while still in use.
func (c *WorkflowV4Coll) ListNamesByAITarget(ctx context.Context, targetType, targetID string) ([]string, error) {
query := bson.M{
"stages.jobs": bson.M{
"$elemMatch": bson.M{
"type": config.JobAI,
"spec.target_type": targetType,
"spec.target_id": targetID,
},
},
}
cursor, err := c.Collection.Find(ctx, query, options.Find().SetProjection(bson.M{"display_name": 1, "name": 1}))
if err != nil {
return nil, err
}
workflows := make([]*models.WorkflowV4, 0)
if err := cursor.All(ctx, &workflows); err != nil {
return nil, err
}

names := make([]string, 0, len(workflows))
for _, workflow := range workflows {
name := workflow.DisplayName
if name == "" {
name = workflow.Name
}
names = append(names, name)
}
return names, nil
}

func (c *WorkflowV4Coll) GetJobNameList(projectName, workflowName, jobType string) ([]string, error) {
workflow := new(models.WorkflowV4)
query := bson.M{"project": projectName, "name": workflowName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/url"
"strings"

"github.com/koderover/zadig/v2/pkg/microservice/aslan/config"
commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb"
templaterepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template"
Expand Down Expand Up @@ -143,13 +142,6 @@ func DeleteAgentIntegration(ctx context.Context, projectName, id string) error {
if _, err := findProjectAgentIntegration(ctx, projectName, id); err != nil {
return e.ErrDeleteAgentIntegration.AddErr(err)
}
workflowNames, err := commonrepo.NewWorkflowV4Coll().ListNamesByAITarget(ctx, config.AITargetTypeAgent, id)
if err != nil {
return e.ErrDeleteAgentIntegration.AddErr(fmt.Errorf("find workflows referencing the agent: %w", err))
}
if len(workflowNames) > 0 {
return e.ErrDeleteAgentIntegration.AddErr(fmt.Errorf("agent is still used by workflow: %s", strings.Join(workflowNames, ", ")))
}
if err := commonrepo.NewAgentIntegrationColl().Delete(ctx, id); err != nil {
return e.ErrDeleteAgentIntegration.AddErr(err)
}
Expand Down
Loading