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

klesh 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 485c984a feat(framework): regenerate plan whenever need to run bp 
(#3858)
485c984a is described below

commit 485c984a0e00d3387ae38e22a24c3461d5c567db
Author: Warren Chen <[email protected]>
AuthorDate: Tue Dec 6 17:05:21 2022 +0800

    feat(framework): regenerate plan whenever need to run bp (#3858)
---
 .../20221201_add_project_pr_metric.go              |  4 ++--
 services/blueprint.go                              | 27 +++++++++++-----------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/models/migrationscripts/20221201_add_project_pr_metric.go 
b/models/migrationscripts/20221201_add_project_pr_metric.go
index ea632810..732a0818 100644
--- a/models/migrationscripts/20221201_add_project_pr_metric.go
+++ b/models/migrationscripts/20221201_add_project_pr_metric.go
@@ -26,9 +26,9 @@ import (
 
 type renameFiledsInProjectPrMetric struct{}
 
-func (u *renameFiledsInProjectPrMetric) Up(baseRes core.BasicRes) errors.Error 
{
+func (u *renameFiledsInProjectPrMetric) Up(basicRes core.BasicRes) 
errors.Error {
        return migrationhelper.AutoMigrateTables(
-               baseRes,
+               basicRes,
                &archived.ProjectPrMetric{},
        )
 }
diff --git a/services/blueprint.go b/services/blueprint.go
index da71f804..9a31d6c1 100644
--- a/services/blueprint.go
+++ b/services/blueprint.go
@@ -138,11 +138,9 @@ func validateBlueprintAndMakePlan(blueprint 
*models.Blueprint) errors.Error {
                        return errors.Default.Wrap(err, fmt.Sprintf("invalid 
projectName: [%s] for the blueprint [%s]", blueprint.ProjectName, 
blueprint.Name))
                }
        }
-
        if strings.ToLower(blueprint.CronConfig) == "manual" {
                blueprint.IsManual = true
        }
-
        if !blueprint.IsManual {
                _, err = cron.ParseStandard(blueprint.CronConfig)
                if err != nil {
@@ -152,7 +150,6 @@ func validateBlueprintAndMakePlan(blueprint 
*models.Blueprint) errors.Error {
        if blueprint.Mode == models.BLUEPRINT_MODE_ADVANCED {
                plan := make(core.PipelinePlan, 0)
                err = errors.Convert(json.Unmarshal(blueprint.Plan, &plan))
-
                if err != nil {
                        return errors.Default.Wrap(err, "invalid plan")
                }
@@ -279,13 +276,12 @@ func ReloadBlueprints(c *cron.Cron) errors.Error {
                        return err
                }
                blueprint := parseBlueprint(dbBlueprint)
-               plan, err := blueprint.UnmarshalPlan()
                if err != nil {
                        blueprintLog.Error(err, failToCreateCronJob)
                        return err
                }
                if _, err := c.AddFunc(blueprint.CronConfig, func() {
-                       pipeline, err := createPipelineByBlueprint(blueprint, 
blueprint.Name, plan)
+                       pipeline, err := createPipelineByBlueprint(blueprint)
                        if err != nil {
                                blueprintLog.Error(err, "run cron job failed")
                        } else {
@@ -303,10 +299,20 @@ func ReloadBlueprints(c *cron.Cron) errors.Error {
        return nil
 }
 
-func createPipelineByBlueprint(blueprint *models.Blueprint, name string, plan 
core.PipelinePlan) (*models.Pipeline, errors.Error) {
+func createPipelineByBlueprint(blueprint *models.Blueprint) (*models.Pipeline, 
errors.Error) {
+       var plan core.PipelinePlan
+       var err errors.Error
+       if blueprint.Mode == models.BLUEPRINT_MODE_NORMAL {
+               plan, err = MakePlanForBlueprint(blueprint)
+       } else {
+               plan, err = blueprint.UnmarshalPlan()
+       }
+       if err != nil {
+               return nil, err
+       }
        newPipeline := models.NewPipeline{}
        newPipeline.Plan = plan
-       newPipeline.Name = name
+       newPipeline.Name = blueprint.Name
        newPipeline.BlueprintId = blueprint.ID
        newPipeline.Labels = blueprint.Labels
        pipeline, err := CreatePipeline(&newPipeline)
@@ -396,12 +402,7 @@ func TriggerBlueprint(id uint64) (*models.Pipeline, 
errors.Error) {
        if err != nil {
                return nil, err
        }
-       plan, err := blueprint.UnmarshalPlan()
-       if err != nil {
-               return nil, err
-       }
-
-       pipeline, err := createPipelineByBlueprint(blueprint, blueprint.Name, 
plan)
+       pipeline, err := createPipelineByBlueprint(blueprint)
        // done
        return pipeline, err
 }

Reply via email to