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

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

Issue 2328733002: Milo: Add ?limit= support to builders (Closed)
Patch Set: Regenerate Created 4 years, 1 month 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 | « milo/api/proto/pb.discovery.go ('k') | milo/appengine/buildbot/html.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 "sort" 10 "sort"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 Duration: duration, 56 Duration: duration,
57 }, 57 },
58 Text: b.Text, 58 Text: b.Text,
59 Blame: blame(b), 59 Blame: blame(b),
60 Revision: b.Sourcestamp.Revision, 60 Revision: b.Sourcestamp.Revision,
61 } 61 }
62 } 62 }
63 63
64 // getBuilds fetches all of the recent builds from the . Note that 64 // getBuilds fetches all of the recent builds from the . Note that
65 // getBuilds() does not perform ACL checks. 65 // getBuilds() does not perform ACL checks.
66 func getBuilds(c context.Context, masterName, builderName string, finished bool) ([]*resp.BuildSummary, error) { 66 func getBuilds(
67 » c context.Context, masterName, builderName string, finished bool, limit int) (
68 » []*resp.BuildSummary, error) {
69
67 // TODO(hinoka): Builder specific structs. 70 // TODO(hinoka): Builder specific structs.
68 result := []*resp.BuildSummary{} 71 result := []*resp.BuildSummary{}
69 q := ds.NewQuery("buildbotBuild") 72 q := ds.NewQuery("buildbotBuild")
70 q = q.Eq("finished", finished) 73 q = q.Eq("finished", finished)
71 q = q.Eq("master", masterName) 74 q = q.Eq("master", masterName)
72 q = q.Eq("builder", builderName) 75 q = q.Eq("builder", builderName)
73 » q = q.Limit(25) // TODO(hinoka): This should be adjustable 76 » q = q.Limit(int32(limit))
74 q = q.Order("-number") 77 q = q.Order("-number")
75 buildbots := []*buildbotBuild{} 78 buildbots := []*buildbotBuild{}
76 err := ds.GetAll(c, q, &buildbots) 79 err := ds.GetAll(c, q, &buildbots)
77 if err != nil { 80 if err != nil {
78 return nil, err 81 return nil, err
79 } 82 }
80 for _, b := range buildbots { 83 for _, b := range buildbots {
81 result = append(result, getBuildSummary(b)) 84 result = append(result, getBuildSummary(b))
82 } 85 }
83 return result, nil 86 return result, nil
(...skipping 22 matching lines...) Expand all
106 results = append(results, cb) 109 results = append(results, cb)
107 } 110 }
108 } 111 }
109 return results 112 return results
110 } 113 }
111 114
112 // builderImpl is the implementation for getting a milo builder page from buildb ot. 115 // builderImpl is the implementation for getting a milo builder page from buildb ot.
113 // This gets: 116 // This gets:
114 // * Current Builds from querying the master json from the datastore. 117 // * Current Builds from querying the master json from the datastore.
115 // * Recent Builds from a cron job that backfills the recent builds. 118 // * Recent Builds from a cron job that backfills the recent builds.
116 func builderImpl(c context.Context, masterName, builderName string) (*resp.Build er, error) { 119 func builderImpl(c context.Context, masterName, builderName string, limit int) ( *resp.Builder, error) {
117 result := &resp.Builder{ 120 result := &resp.Builder{
118 Name: builderName, 121 Name: builderName,
119 } 122 }
120 master, t, err := getMasterJSON(c, masterName) 123 master, t, err := getMasterJSON(c, masterName)
121 switch { 124 switch {
122 case err == ds.ErrNoSuchEntity: 125 case err == ds.ErrNoSuchEntity:
123 return nil, errMasterNotFound 126 return nil, errMasterNotFound
124 case err != nil: 127 case err != nil:
125 return nil, err 128 return nil, err
126 } 129 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 164 }
162 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour ce.Changes)) 165 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour ce.Changes))
163 for j, cm := range pb.Source.Changes { 166 for j, cm := range pb.Source.Changes {
164 result.PendingBuilds[i].Blame[j] = &resp.Commit{ 167 result.PendingBuilds[i].Blame[j] = &resp.Commit{
165 AuthorEmail: cm.Who, 168 AuthorEmail: cm.Who,
166 CommitURL: cm.Revlink, 169 CommitURL: cm.Revlink,
167 } 170 }
168 } 171 }
169 } 172 }
170 173
171 » recentBuilds, err := getBuilds(c, masterName, builderName, true) 174 » recentBuilds, err := getBuilds(c, masterName, builderName, true, limit)
172 if err != nil { 175 if err != nil {
173 return nil, err 176 return nil, err
174 } 177 }
175 » currentBuilds, err := getBuilds(c, masterName, builderName, false) 178 » currentBuilds, err := getBuilds(c, masterName, builderName, false, 0)
176 if err != nil { 179 if err != nil {
177 return nil, err 180 return nil, err
178 } 181 }
179 logging.Debugf(c, "Number of current builds: %d", len(currentBuilds)) 182 logging.Debugf(c, "Number of current builds: %d", len(currentBuilds))
180 // TODO(hinoka): This works, but there's a lot of junk data from 183 // TODO(hinoka): This works, but there's a lot of junk data from
181 // masters with unclean shutdown. Need to implement a cleanup 184 // masters with unclean shutdown. Need to implement a cleanup
182 // procedure of some sort. Once that is done, set: 185 // procedure of some sort. Once that is done, set:
183 // result.CurrentBuilds = currentBuilds 186 // result.CurrentBuilds = currentBuilds
184 187
185 for _, fb := range recentBuilds { 188 for _, fb := range recentBuilds {
186 // Yes recent builds is synonymous with finished builds. 189 // Yes recent builds is synonymous with finished builds.
187 // TODO(hinoka): Implement limits. 190 // TODO(hinoka): Implement limits.
188 if fb != nil { 191 if fb != nil {
189 result.FinishedBuilds = append(result.FinishedBuilds, fb ) 192 result.FinishedBuilds = append(result.FinishedBuilds, fb )
190 } 193 }
191 } 194 }
192 return result, nil 195 return result, nil
193 } 196 }
OLDNEW
« no previous file with comments | « milo/api/proto/pb.discovery.go ('k') | milo/appengine/buildbot/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698