Skip to content

Commit 5fa4200

Browse files
fix(framework): add lock when creating pipeline (#7733) (#7736)
Co-authored-by: Lynwee <1507509064@qq.com>
1 parent d15f7b4 commit 5fa4200

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

backend/server/services/blueprint.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func MakePlanForBlueprint(blueprint *models.Blueprint, syncPolicy *models.SyncPo
367367
if err != nil {
368368
return nil, err
369369
}
370-
return SequencializePipelinePlans(blueprint.BeforePlan, plan, blueprint.AfterPlan), nil
370+
return SequentializePipelinePlans(blueprint.BeforePlan, plan, blueprint.AfterPlan), nil
371371
}
372372

373373
// ParallelizePipelinePlans merges multiple pipelines into one unified plan
@@ -388,9 +388,9 @@ func ParallelizePipelinePlans(plans ...models.PipelinePlan) models.PipelinePlan
388388
return merged
389389
}
390390

391-
// SequencializePipelinePlans merges multiple pipelines into one unified plan
392-
// by assuming they must be executed in sequencial order
393-
func SequencializePipelinePlans(plans ...models.PipelinePlan) models.PipelinePlan {
391+
// SequentializePipelinePlans merges multiple pipelines into one unified plan
392+
// by assuming they must be executed in sequential order
393+
func SequentializePipelinePlans(plans ...models.PipelinePlan) models.PipelinePlan {
394394
merged := make(models.PipelinePlan, 0)
395395
// iterate all pipelineTasks and try to merge them into `merged`
396396
for _, plan := range plans {

backend/server/services/blueprint_makeplan_v200.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func GeneratePlanJsonV200(
132132
}
133133
}
134134
}
135-
plan := SequencializePipelinePlans(
135+
plan := SequentializePipelinePlans(
136136
planForProjectMapping,
137137
ParallelizePipelinePlans(sourcePlans...),
138138
ParallelizePipelinePlans(metricPlans...),

backend/server/services/pipeline_helper.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package services
1919

2020
import (
2121
"fmt"
22+
"sync"
2223
"time"
2324

2425
"github.com/apache/incubator-devlake/core/dal"
@@ -27,8 +28,12 @@ import (
2728
"github.com/apache/incubator-devlake/helpers/dbhelper"
2829
)
2930

31+
var createDbPipelineLock sync.Mutex
32+
3033
// CreateDbPipeline returns a NewPipeline
3134
func CreateDbPipeline(newPipeline *models.NewPipeline) (pipeline *models.Pipeline, err errors.Error) {
35+
createDbPipelineLock.Lock()
36+
defer createDbPipelineLock.Unlock()
3237
pipeline = &models.Pipeline{}
3338
txHelper := dbhelper.NewTxHelper(basicRes, &err)
3439
defer txHelper.End()
@@ -49,7 +54,7 @@ func CreateDbPipeline(newPipeline *models.NewPipeline) (pipeline *models.Pipelin
4954
dal.From(&models.Pipeline{}),
5055
dal.Where("blueprint_id = ? AND status IN ?", newPipeline.BlueprintId, models.PendingTaskStatus),
5156
))
52-
// some pipeline is ruunning , get the detail and output them.
57+
// some pipeline is running, get the detail and output them.
5358
if count > 0 {
5459
return nil, errors.BadInput.New("there are pending pipelines of current blueprint already")
5560
}

0 commit comments

Comments
 (0)