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

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

Issue 2929703002: [api] Regenerate remote APIs. (Closed)
Patch Set: fix Created 3 years, 6 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 | « common/api/swarming/swarming/v1/swarming-api.json ('k') | milo/appengine/buildbucket/common.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 buildbucket 5 package buildbucket
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "net/url" 10 "net/url"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 func(err error, wait time.Duration) { 49 func(err error, wait time.Duration) {
50 logging.WithError(err).Warningf(c, "buildbucket search r equest failed transiently, will retry in %s", wait) 50 logging.WithError(err).Warningf(c, "buildbucket search r equest failed transiently, will retry in %s", wait)
51 }) 51 })
52 return res, err 52 return res, err
53 } 53 }
54 54
55 // fetchBuilds fetches builds given a criteria. 55 // fetchBuilds fetches builds given a criteria.
56 // The returned builds are sorted by build creation descending. 56 // The returned builds are sorted by build creation descending.
57 // count defines maximum number of builds to fetch; if <0, defaults to 100. 57 // count defines maximum number of builds to fetch; if <0, defaults to 100.
58 func fetchBuilds(c context.Context, client *buildbucket.Service, bucket, builder , 58 func fetchBuilds(c context.Context, client *buildbucket.Service, bucket, builder ,
59 » status string, count int) ([]*buildbucket.ApiBuildMessage, error) { 59 » status string, count int) ([]*buildbucket.ApiCommonBuildMessage, error) {
60 60
61 req := client.Search() 61 req := client.Search()
62 req.Bucket(bucket) 62 req.Bucket(bucket)
63 req.Status(status) 63 req.Status(status)
64 req.Tag("builder:" + builder) 64 req.Tag("builder:" + builder)
65 65
66 if count < 0 { 66 if count < 0 {
67 count = 100 67 count = 100
68 } 68 }
69 69
70 » fetched := make([]*buildbucket.ApiBuildMessage, 0, count) 70 » fetched := make([]*buildbucket.ApiCommonBuildMessage, 0, count)
71 start := clock.Now(c) 71 start := clock.Now(c)
72 for len(fetched) < count { 72 for len(fetched) < count {
73 req.MaxBuilds(int64(count - len(fetched))) 73 req.MaxBuilds(int64(count - len(fetched)))
74 74
75 res, err := search(c, client, req) 75 res, err := search(c, client, req)
76 switch { 76 switch {
77 case err != nil: 77 case err != nil:
78 return fetched, err 78 return fetched, err
79 case res.Error != nil: 79 case res.Error != nil:
80 return fetched, fmt.Errorf(res.Error.Message) 80 return fetched, fmt.Errorf(res.Error.Message)
81 } 81 }
82 82
83 fetched = append(fetched, res.Builds...) 83 fetched = append(fetched, res.Builds...)
84 84
85 if len(res.Builds) == 0 || res.NextCursor == "" { 85 if len(res.Builds) == 0 || res.NextCursor == "" {
86 break 86 break
87 } 87 }
88 req.StartCursor(res.NextCursor) 88 req.StartCursor(res.NextCursor)
89 } 89 }
90 logging.Debugf(c, "Fetched %d %s builds in %s", len(fetched), status, cl ock.Since(c, start)) 90 logging.Debugf(c, "Fetched %d %s builds in %s", len(fetched), status, cl ock.Since(c, start))
91 return fetched, nil 91 return fetched, nil
92 } 92 }
93 93
94 // toMiloBuild converts a buildbucket build to a milo build. 94 // toMiloBuild converts a buildbucket build to a milo build.
95 // In case of an error, returns a build with a description of the error 95 // In case of an error, returns a build with a description of the error
96 // and logs the error. 96 // and logs the error.
97 func toMiloBuild(c context.Context, build *buildbucket.ApiBuildMessage) *resp.Bu ildSummary { 97 func toMiloBuild(c context.Context, build *buildbucket.ApiCommonBuildMessage) *r esp.BuildSummary {
98 // Parsing of parameters and result details is best effort. 98 // Parsing of parameters and result details is best effort.
99 var params buildParameters 99 var params buildParameters
100 if err := json.NewDecoder(strings.NewReader(build.ParametersJson)).Decod e(&params); err != nil { 100 if err := json.NewDecoder(strings.NewReader(build.ParametersJson)).Decod e(&params); err != nil {
101 logging.Errorf(c, "Could not parse parameters of build %d: %s", build.Id, err) 101 logging.Errorf(c, "Could not parse parameters of build %d: %s", build.Id, err)
102 } 102 }
103 var resultDetails resultDetails 103 var resultDetails resultDetails
104 if err := json.NewDecoder(strings.NewReader(build.ResultDetailsJson)).De code(&resultDetails); err != nil { 104 if err := json.NewDecoder(strings.NewReader(build.ResultDetailsJson)).De code(&resultDetails); err != nil {
105 logging.Errorf(c, "Could not parse result details of build %d: % s", build.Id, err) 105 logging.Errorf(c, "Could not parse result details of build %d: % s", build.Id, err)
106 } 106 }
107 107
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC() 289 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC()
290 } 290 }
291 291
292 type newBuildsFirst []*resp.BuildSummary 292 type newBuildsFirst []*resp.BuildSummary
293 293
294 func (a newBuildsFirst) Len() int { return len(a) } 294 func (a newBuildsFirst) Len() int { return len(a) }
295 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 295 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
296 func (a newBuildsFirst) Less(i, j int) bool { 296 func (a newBuildsFirst) Less(i, j int) bool {
297 return a[i].PendingTime.Started.After(a[j].PendingTime.Started) 297 return a[i].PendingTime.Started.After(a[j].PendingTime.Started)
298 } 298 }
OLDNEW
« no previous file with comments | « common/api/swarming/swarming/v1/swarming-api.json ('k') | milo/appengine/buildbucket/common.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698