Moved proc id changes closer to each other

This commit is contained in:
Laszlo Fogas 2019-06-05 10:36:16 +02:00
parent 4323148a85
commit dbfbd15238
3 changed files with 32 additions and 37 deletions

View file

@ -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{

View file

@ -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

View file

@ -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)
}