From dbfbd1523856589a277e591d753838402195e2ec Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Wed, 5 Jun 2019 10:36:16 +0200 Subject: [PATCH] Moved proc id changes closer to each other --- server/hook.go | 29 ----------------------------- server/procBuilder.go | 35 ++++++++++++++++++++++++++++++++--- server/procBuilder_test.go | 5 ----- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/server/hook.go b/server/hook.go index 5a71ab9d4..a15f4a3c5 100644 --- a/server/hook.go +++ b/server/hook.go @@ -253,8 +253,6 @@ func PostHook(c *gin.Context) { return } - setBuildProcs(build, buildItems) - err = store.FromContext(c).ProcCreate(build.Procs) if err != nil { logrus.Errorf("error persisting procs %s/%d: %s", repo.FullName, build.Number, err) @@ -286,33 +284,6 @@ func findOrPersistPipelineConfig(repo *model.Repo, remoteYamlConfig []byte) (*mo return conf, nil } -func setBuildProcs(build *model.Build, buildItems []*buildItem) { - pcounter := len(buildItems) - for _, item := range buildItems { - build.Procs = append(build.Procs, item.Proc) - item.Proc.BuildID = build.ID - - for _, stage := range item.Config.Stages { - var gid int - for _, step := range stage.Steps { - pcounter++ - if gid == 0 { - gid = pcounter - } - proc := &model.Proc{ - BuildID: build.ID, - Name: step.Alias, - PID: pcounter, - PPID: item.Proc.PID, - PGID: gid, - State: model.StatusPending, - } - build.Procs = append(build.Procs, proc) - } - } - } -} - func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo) { message := pubsub.Message{ Labels: map[string]string{ diff --git a/server/procBuilder.go b/server/procBuilder.go index 86cd004d6..e12c05df8 100644 --- a/server/procBuilder.go +++ b/server/procBuilder.go @@ -53,7 +53,7 @@ type buildItem struct { func (b *procBuilder) Build() ([]*buildItem, error) { var items []*buildItem - for _, y := range b.Yamls { + for j, y := range b.Yamls { axes, err := matrix.ParseString(y) if err != nil { return nil, err @@ -65,8 +65,8 @@ func (b *procBuilder) Build() ([]*buildItem, error) { for i, axis := range axes { proc := &model.Proc{ BuildID: b.Curr.ID, - PID: i + 1, - PGID: i + 1, + PID: j + i + 1, + PGID: j + i + 1, State: model.StatusPending, Environ: axis, } @@ -174,9 +174,38 @@ func (b *procBuilder) Build() ([]*buildItem, error) { } } + setBuildProcs(b.Curr, items) + return items, nil } +func setBuildProcs(build *model.Build, buildItems []*buildItem) { + pcounter := len(buildItems) + for _, item := range buildItems { + build.Procs = append(build.Procs, item.Proc) + item.Proc.BuildID = build.ID + + for _, stage := range item.Config.Stages { + var gid int + for _, step := range stage.Steps { + pcounter++ + if gid == 0 { + gid = pcounter + } + proc := &model.Proc{ + BuildID: build.ID, + Name: step.Alias, + PID: pcounter, + PPID: item.Proc.PID, + PGID: gid, + State: model.StatusPending, + } + build.Procs = append(build.Procs, proc) + } + } + } +} + // return the metadata from the cli context. func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.Proc, link string) frontend.Metadata { host := link diff --git a/server/procBuilder_test.go b/server/procBuilder_test.go index a8f1c7551..9ba858ed9 100644 --- a/server/procBuilder_test.go +++ b/server/procBuilder_test.go @@ -83,9 +83,4 @@ func TestMultiPipeline(t *testing.T) { if len(buildItems) != 2 { t.Fatal("Should have generated 2 buildItems") } - - // fmt.Println(buildItems) - // build := &model.Build{} - // setBuildProcs(build, buildItems) - // fmt.Println(build) }