From e083199384e1d0cd389a8e092314fd6d644e1279 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 8 Jan 2015 15:34:45 -0800 Subject: [PATCH] dashboard/coordinator: notify dashboard when we're building Fixes golang/go#9494 Change-Id: Ib9451d41b2dd02d30d2efddbc0ec410a34bdb42c Reviewed-on: https://go-review.googlesource.com/2583 Reviewed-by: Andrew Gerrand --- dashboard/coordinator/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dashboard/coordinator/main.go b/dashboard/coordinator/main.go index e31aad2e..9713e8b4 100644 --- a/dashboard/coordinator/main.go +++ b/dashboard/coordinator/main.go @@ -80,6 +80,7 @@ var ( projectID string projectZone string computeService *compute.Service + externalIP string ) func initGCE() error { @@ -101,6 +102,10 @@ func initGCE() error { return errors.New("The coordinator is not running with access to read and write Compute resources. VM support disabled.") } + externalIP, err = metadata.ExternalIP() + if err != nil { + return fmt.Errorf("ExternalIP: %v", err) + } ts := google.ComputeTokenSource("default") computeService, _ = compute.New(oauth2.NewClient(oauth2.NoContext, ts)) return nil @@ -163,6 +168,29 @@ func (b *buildConfig) recordResult(ok bool, hash, buildLog string, runTime time. return dash("POST", "result", args, req, nil) } +// pingDashboard is a goroutine that periodically POSTS to build.golang.org/building +// to let it know that we're still working on a build. +func pingDashboard(st *buildStatus) { + u := "https://build.golang.org/building?" + url.Values{ + "builder": []string{st.name}, + "key": []string{builderKey(st.name)}, + "hash": []string{st.rev}, + "url": []string{fmt.Sprintf("http://%v/logs?name=%s&rev=%s&st=%p", externalIP, st.name, st.rev, st)}, + }.Encode() + for { + st.mu.Lock() + done := st.done + st.mu.Unlock() + if !done.IsZero() { + return + } + if res, _ := http.PostForm(u, nil); res != nil { + res.Body.Close() + } + time.Sleep(60 * time.Second) + } +} + type watchConfig struct { repo string // "https://go.googlesource.com/go" dash string // "https://build.golang.org/" (must end in /) @@ -290,6 +318,7 @@ func main() { conf := builders[work.name] if st, err := startBuilding(conf, work.rev); err == nil { setStatus(work, st) + go pingDashboard(st) } else { log.Printf("Error starting to build %v: %v", work, err) }