From 16a07e660ad24d3306f64ff6504aa7e50928a453 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 4 Apr 2017 18:30:06 +0900 Subject: [PATCH] enable granular step data for matrix --- server/build.go | 9 +++++++-- server/hook.go | 9 +++++++-- server/rpc.go | 22 ++++++++++++++-------- store/datastore/ddl/mysql/13.sql | 1 - store/datastore/ddl/postgres/13.sql | 1 - store/datastore/ddl/sqlite3/13.sql | 1 - 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/server/build.go b/server/build.go index 89b34506e..a4c6845cc 100644 --- a/server/build.go +++ b/server/build.go @@ -258,6 +258,8 @@ func PostApproval(c *gin.Context) { // // publish topic // + buildCopy := *build + buildCopy.Procs = model.Tree(buildCopy.Procs) message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, @@ -267,10 +269,11 @@ func PostApproval(c *gin.Context) { message.Data, _ = json.Marshal(model.Event{ Type: model.Enqueued, Repo: *repo, - Build: *build, + Build: buildCopy, }) // TODO remove global reference config.pubsub.Publish(c, "topic/events", message) + // // end publish topic // @@ -517,6 +520,8 @@ func PostBuild(c *gin.Context) { // // publish topic // + buildCopy := *build + buildCopy.Procs = model.Tree(buildCopy.Procs) message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, @@ -526,7 +531,7 @@ func PostBuild(c *gin.Context) { message.Data, _ = json.Marshal(model.Event{ Type: model.Enqueued, Repo: *repo, - Build: *build, + Build: buildCopy, }) // TODO remove global reference config.pubsub.Publish(c, "topic/events", message) diff --git a/server/hook.go b/server/hook.go index 3ea50b2b9..06762dab7 100644 --- a/server/hook.go +++ b/server/hook.go @@ -293,7 +293,10 @@ func PostHook(c *gin.Context) { } } } - store.FromContext(c).ProcCreate(build.Procs) + err = store.FromContext(c).ProcCreate(build.Procs) + if err != nil { + logrus.Errorf("error persisting procs %s/%d: %s", repo.FullName, build.Number, err) + } // // publish topic @@ -304,10 +307,12 @@ func PostHook(c *gin.Context) { "private": strconv.FormatBool(repo.IsPrivate), }, } + buildCopy := *build + buildCopy.Procs = model.Tree(buildCopy.Procs) message.Data, _ = json.Marshal(model.Event{ Type: model.Enqueued, Repo: *repo, - Build: *build, + Build: buildCopy, }) // TODO remove global reference config.pubsub.Publish(c, "topic/events", message) diff --git a/server/rpc.go b/server/rpc.go index 0848e8403..6be318816 100644 --- a/server/rpc.go +++ b/server/rpc.go @@ -153,6 +153,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error { } build.Procs, _ = s.store.ProcList(build) + build.Procs = model.Tree(build.Procs) message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, @@ -305,29 +306,34 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error { log.Printf("error: done: cannot ack proc_id %d: %s", procID, err) } - done := false - status := model.StatusSuccess // TODO handle this error procs, _ := s.store.ProcList(build) for _, p := range procs { if p.Running() && p.PPID == proc.PID { p.State = model.StatusSkipped if p.Started != 0 { - p.State = model.StatusKilled + p.State = model.StatusSuccess // for deamons that are killed p.Stopped = proc.Stopped } if err := s.store.ProcUpdate(p); err != nil { log.Printf("error: done: cannot update proc_id %d child state: %s", p.ID, err) } } - if !p.Running() && p.PPID == 0 { - done = true + } + + running := false + status := model.StatusSuccess + for _, p := range procs { + if p.PPID == 0 { + if p.Running() { + running = true + } if p.Failing() { - status = model.StatusFailure + status = p.State } } } - if done { + if !running { build.Status = status build.Finished = proc.Stopped if err := s.store.UpdateBuild(build); err != nil { @@ -339,7 +345,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error { log.Printf("error: done: cannot close build_id %d logger: %s", proc.ID, err) } - build.Procs = procs + build.Procs = model.Tree(procs) message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, diff --git a/store/datastore/ddl/mysql/13.sql b/store/datastore/ddl/mysql/13.sql index 0bc466a2f..d03759bdf 100644 --- a/store/datastore/ddl/mysql/13.sql +++ b/store/datastore/ddl/mysql/13.sql @@ -16,7 +16,6 @@ CREATE TABLE procs ( ,proc_platform VARCHAR(250) ,proc_environ VARCHAR(2000) ,UNIQUE(proc_build_id, proc_pid) -,UNIQUE(proc_build_id, proc_name) ); CREATE INDEX proc_build_ix ON procs (proc_build_id); diff --git a/store/datastore/ddl/postgres/13.sql b/store/datastore/ddl/postgres/13.sql index bf11aaa92..f01954205 100644 --- a/store/datastore/ddl/postgres/13.sql +++ b/store/datastore/ddl/postgres/13.sql @@ -17,7 +17,6 @@ CREATE TABLE procs ( ,proc_environ VARCHAR(2000) ,UNIQUE(proc_build_id, proc_pid) -,UNIQUE(proc_build_id, proc_name) ); CREATE INDEX proc_build_ix ON procs (proc_build_id); diff --git a/store/datastore/ddl/sqlite3/13.sql b/store/datastore/ddl/sqlite3/13.sql index 114698919..e57ca6f9b 100644 --- a/store/datastore/ddl/sqlite3/13.sql +++ b/store/datastore/ddl/sqlite3/13.sql @@ -16,7 +16,6 @@ CREATE TABLE procs ( ,proc_platform TEXT ,proc_environ TEXT ,UNIQUE(proc_build_id, proc_pid) -,UNIQUE(proc_build_id, proc_name) ); CREATE INDEX proc_build_ix ON procs (proc_build_id);