Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: milo/appengine/buildbot/builder.go

Issue 2409953002: Milo: Display pending builds (Closed)
Patch Set: Review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | milo/appengine/buildbot/structs.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "os"
11 "sort" 10 "sort"
12 "strings" 11 "strings"
13 "time" 12 "time"
14 13
15 ds "github.com/luci/gae/service/datastore" 14 ds "github.com/luci/gae/service/datastore"
16 15
17 "github.com/luci/luci-go/common/clock" 16 "github.com/luci/luci-go/common/clock"
18 "github.com/luci/luci-go/common/logging" 17 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/milo/api/resp" 18 "github.com/luci/luci-go/milo/api/resp"
20 "golang.org/x/net/context" 19 "golang.org/x/net/context"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if clock.Now(c).Sub(t) > 2*time.Minute { 125 if clock.Now(c).Sub(t) > 2*time.Minute {
127 warning := fmt.Sprintf( 126 warning := fmt.Sprintf(
128 "WARNING: Master data is stale (last updated %s)", t) 127 "WARNING: Master data is stale (last updated %s)", t)
129 logging.Warningf(c, warning) 128 logging.Warningf(c, warning)
130 result.Warning = warning 129 result.Warning = warning
131 } 130 }
132 131
133 s, _ := json.Marshal(master) 132 s, _ := json.Marshal(master)
134 logging.Debugf(c, "Master: %s", s) 133 logging.Debugf(c, "Master: %s", s)
135 134
136 » _, ok := master.Builders[builderName] 135 » p, ok := master.Builders[builderName]
137 if !ok { 136 if !ok {
138 // This long block is just to return a good error message when a n invalid 137 // This long block is just to return a good error message when a n invalid
139 // buildbot builder is specified. 138 // buildbot builder is specified.
140 keys := make([]string, 0, len(master.Builders)) 139 keys := make([]string, 0, len(master.Builders))
141 for k := range master.Builders { 140 for k := range master.Builders {
142 keys = append(keys, k) 141 keys = append(keys, k)
143 } 142 }
144 sort.Strings(keys) 143 sort.Strings(keys)
145 avail := strings.Join(keys, "\n") 144 avail := strings.Join(keys, "\n")
146 return nil, fmt.Errorf( 145 return nil, fmt.Errorf(
147 "Cannot find builder %s in master %s.\nAvailable builder s: \n%s", 146 "Cannot find builder %s in master %s.\nAvailable builder s: \n%s",
148 builderName, masterName, avail) 147 builderName, masterName, avail)
149 } 148 }
149 // Extract pending builds out of the master json.
150 result.PendingBuilds = make([]*resp.BuildSummary, len(p.PendingBuildStat es))
151 logging.Debugf(c, "Number of pending builds: %d", len(p.PendingBuildStat es))
152 for i, pb := range p.PendingBuildStates {
153 start := time.Unix(int64(pb.SubmittedAt), 0)
154 result.PendingBuilds[i] = &resp.BuildSummary{
155 PendingTime: resp.Interval{
156 Started: start,
157 Duration: time.Now().Sub(start),
158 },
159 }
160 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour ce.Changes))
161 for j, cm := range pb.Source.Changes {
162 result.PendingBuilds[i].Blame[j] = &resp.Commit{
163 AuthorEmail: cm.Who,
164 CommitURL: cm.Revlink,
165 }
166 }
167 }
150 168
151 recentBuilds, err := getBuilds(c, masterName, builderName, true) 169 recentBuilds, err := getBuilds(c, masterName, builderName, true)
152 if err != nil { 170 if err != nil {
153 » » return nil, err // Or maybe not? 171 » » return nil, err
154 } 172 }
155 » currentBuilds := getCurrentBuilds(c, master, builderName) 173 » currentBuilds, err := getBuilds(c, masterName, builderName, false)
156 » fmt.Fprintf(os.Stderr, "Number of current builds: %d\n", len(currentBuil ds)) 174 » if err != nil {
157 » result.CurrentBuilds = currentBuilds 175 » » return nil, err
176 » }
177 » logging.Debugf(c, "Number of current builds: %d", len(currentBuilds))
178 » // TODO(hinoka): This works, but there's a lot of junk data from
179 » // masters with unclean shutdown. Need to implement a cleanup
180 » // procedure of some sort. Once that is done, set:
181 » // result.CurrentBuilds = currentBuilds
182
158 for _, fb := range recentBuilds { 183 for _, fb := range recentBuilds {
159 // Yes recent builds is synonymous with finished builds. 184 // Yes recent builds is synonymous with finished builds.
160 // TODO(hinoka): Implement limits. 185 // TODO(hinoka): Implement limits.
161 if fb != nil { 186 if fb != nil {
162 result.FinishedBuilds = append(result.FinishedBuilds, fb ) 187 result.FinishedBuilds = append(result.FinishedBuilds, fb )
163 } 188 }
164 } 189 }
165 return result, nil 190 return result, nil
166 } 191 }
OLDNEW
« no previous file with comments | « no previous file | milo/appengine/buildbot/structs.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698