Skip to content

Commit 0175ef4

Browse files
authored
Merge branch 'main' into fix-s3-empty-validation
2 parents 8d25b0f + 7b78750 commit 0175ef4

File tree

12 files changed

+112
-1
lines changed

12 files changed

+112
-1
lines changed

backend/core/models/blueprint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Blueprint struct {
4141
AfterPlan PipelinePlan `json:"afterPlan" gorm:"serializer:encdec"`
4242
Labels []string `json:"labels" gorm:"-"`
4343
Connections []*BlueprintConnection `json:"connections" gorm:"-"`
44+
Priority int `json:"priority"` // greater is higher
4445
SyncPolicy `gorm:"embedded"`
4546
common.Model `swaggerignore:"true"`
4647
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
"github.com/apache/incubator-devlake/helpers/migrationhelper"
25+
)
26+
27+
var _ plugin.MigrationScript = (*addPipelinePriority)(nil)
28+
29+
type addPipelinePriority struct{}
30+
31+
type blueprint20250813 struct {
32+
Priority int `json:"priority"`
33+
}
34+
35+
func (blueprint20250813) TableName() string {
36+
return "_devlake_blueprints"
37+
}
38+
39+
type pipeline20250813 struct {
40+
Priority int `json:"priority"`
41+
}
42+
43+
func (pipeline20250813) TableName() string {
44+
return "_devlake_pipelines"
45+
}
46+
47+
func (script *addPipelinePriority) Up(basicRes context.BasicRes) errors.Error {
48+
return migrationhelper.AutoMigrateTables(basicRes, new(blueprint20250813), new(pipeline20250813))
49+
}
50+
51+
func (*addPipelinePriority) Version() uint64 {
52+
return 20250813151534
53+
}
54+
55+
func (*addPipelinePriority) Name() string {
56+
return "add priority to blueprints and pipelines"
57+
}

backend/core/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,6 @@ func All() []plugin.MigrationScript {
139139
new(increaseCqIssueComponentLength),
140140
new(extendFieldSizeForCq),
141141
new(addIssueFixVerion),
142+
new(addPipelinePriority),
142143
}
143144
}

backend/core/models/pipeline.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type Pipeline struct {
6666
SpentSeconds int `json:"spentSeconds"`
6767
Stage int `json:"stage"`
6868
Labels []string `json:"labels" gorm:"-"`
69+
Priority int `json:"priority"` // greater is higher
6970
SyncPolicy `gorm:"embedded"`
7071
}
7172

@@ -75,6 +76,7 @@ type NewPipeline struct {
7576
Name string `json:"name"`
7677
Plan PipelinePlan `json:"plan" swaggertype:"array,string" example:"please check api /pipelines/<PLUGIN_NAME>/pipeline-plan"`
7778
Labels []string `json:"labels"`
79+
Priority int `json:"priority"` // greater is higher
7880
BlueprintId uint64
7981
SyncPolicy `gorm:"embedded"`
8082
}

backend/plugins/org/impl/impl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (p Org) SubTaskMetas() []plugin.SubTaskMeta {
6161
return []plugin.SubTaskMeta{
6262
tasks.ConnectUserAccountsExactMeta,
6363
tasks.SetProjectMappingMeta,
64+
tasks.SleepMeta,
6465
}
6566
}
6667

backend/plugins/org/tasks/sleep.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package tasks
19+
20+
import (
21+
"time"
22+
23+
"github.com/apache/incubator-devlake/core/errors"
24+
"github.com/apache/incubator-devlake/core/plugin"
25+
)
26+
27+
var SleepMeta = plugin.SubTaskMeta{
28+
Name: "sleep",
29+
EntryPoint: Sleep,
30+
EnabledByDefault: false,
31+
Description: "for debugging only",
32+
DomainTypes: []string{plugin.DOMAIN_TYPE_CROSS},
33+
}
34+
35+
// SetProjectMapping binds projects and scopes
36+
func Sleep(taskCtx plugin.SubTaskContext) errors.Error {
37+
data := taskCtx.GetData().(*TaskData)
38+
time.Sleep(time.Duration(data.Options.SleepSeconds) * time.Second)
39+
return nil
40+
}

backend/plugins/org/tasks/task_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import "github.com/apache/incubator-devlake/core/plugin"
2222
type Options struct {
2323
ConnectionId uint64 `json:"connectionId"`
2424
ProjectMappings []ProjectMapping `json:"projectMappings"`
25+
SleepSeconds uint64 `json:"sleepSeconds"`
2526
}
2627

2728
// ProjectMapping represents the relations between project and scopes

backend/server/services/blueprint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ func createPipelineByBlueprint(blueprint *models.Blueprint, syncPolicy *models.S
327327
newPipeline.Name = blueprint.Name
328328
newPipeline.BlueprintId = blueprint.ID
329329
newPipeline.Labels = blueprint.Labels
330+
newPipeline.Priority = blueprint.Priority
330331
newPipeline.SyncPolicy = blueprint.SyncPolicy
331332

332333
// if the plan is empty, we should not create the pipeline

backend/server/services/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func dequeuePipeline(runningParallelLabels []string) (pipeline *models.Pipeline,
273273
dal.Groupby("id"),
274274
dal.Having("count(_devlake_pipeline_labels.name)=0"),
275275
dal.Select("id"),
276-
dal.Orderby("id ASC"),
276+
dal.Orderby("priority DESC, id ASC"),
277277
dal.Limit(1),
278278
)
279279
if err == nil {

backend/server/services/pipeline_helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func CreateDbPipeline(newPipeline *models.NewPipeline) (pipeline *models.Pipelin
6767
Message: "",
6868
SpentSeconds: 0,
6969
Plan: newPipeline.Plan,
70+
Priority: newPipeline.Priority,
7071
SyncPolicy: newPipeline.SyncPolicy,
7172
}
7273
if newPipeline.BlueprintId != 0 {

0 commit comments

Comments
 (0)