OLD | NEW |
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" |
11 "os" | 11 "os" |
12 "path" | 12 "path" |
13 "path/filepath" | 13 "path/filepath" |
14 "strconv" | 14 "strconv" |
15 "strings" | 15 "strings" |
16 "time" | 16 "time" |
17 | 17 |
18 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
19 "google.golang.org/api/googleapi" | 19 "google.golang.org/api/googleapi" |
20 | 20 |
21 "github.com/luci/gae/service/info" | 21 "github.com/luci/gae/service/info" |
22 "github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1" | 22 "github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1" |
23 "github.com/luci/luci-go/common/clock" | 23 "github.com/luci/luci-go/common/clock" |
24 "github.com/luci/luci-go/common/errors" | 24 "github.com/luci/luci-go/common/errors" |
25 "github.com/luci/luci-go/common/logging" | 25 "github.com/luci/luci-go/common/logging" |
26 "github.com/luci/luci-go/common/retry" | 26 "github.com/luci/luci-go/common/retry" |
| 27 "github.com/luci/luci-go/common/retry/transient" |
27 "github.com/luci/luci-go/common/sync/parallel" | 28 "github.com/luci/luci-go/common/sync/parallel" |
28 | 29 |
29 "github.com/luci/luci-go/milo/api/resp" | 30 "github.com/luci/luci-go/milo/api/resp" |
30 "github.com/luci/luci-go/milo/common" | 31 "github.com/luci/luci-go/milo/common" |
31 "github.com/luci/luci-go/milo/common/model" | 32 "github.com/luci/luci-go/milo/common/model" |
32 ) | 33 ) |
33 | 34 |
34 // search executes the search request with retries and exponential back-off. | 35 // search executes the search request with retries and exponential back-off. |
35 func search(c context.Context, client *buildbucket.Service, req *buildbucket.Sea
rchCall) ( | 36 func search(c context.Context, client *buildbucket.Service, req *buildbucket.Sea
rchCall) ( |
36 *buildbucket.ApiSearchResponseMessage, error) { | 37 *buildbucket.ApiSearchResponseMessage, error) { |
37 | 38 |
38 var res *buildbucket.ApiSearchResponseMessage | 39 var res *buildbucket.ApiSearchResponseMessage |
39 err := retry.Retry( | 40 err := retry.Retry( |
40 c, | 41 c, |
41 » » retry.TransientOnly(retry.Default), | 42 » » transient.Only(retry.Default), |
42 func() error { | 43 func() error { |
43 var err error | 44 var err error |
44 res, err = req.Do() | 45 res, err = req.Do() |
45 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Co
de >= 500 { | 46 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Co
de >= 500 { |
46 » » » » err = errors.WrapTransient(apiErr) | 47 » » » » err = transient.Tag.Apply(apiErr) |
47 } | 48 } |
48 return err | 49 return err |
49 }, | 50 }, |
50 func(err error, wait time.Duration) { | 51 func(err error, wait time.Duration) { |
51 logging.WithError(err).Warningf(c, "buildbucket search r
equest failed transiently, will retry in %s", wait) | 52 logging.WithError(err).Warningf(c, "buildbucket search r
equest failed transiently, will retry in %s", wait) |
52 }) | 53 }) |
53 return res, err | 54 return res, err |
54 } | 55 } |
55 | 56 |
56 // fetchBuilds fetches builds given a criteria. | 57 // fetchBuilds fetches builds given a criteria. |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC() | 288 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC() |
288 } | 289 } |
289 | 290 |
290 type newBuildsFirst []*resp.BuildSummary | 291 type newBuildsFirst []*resp.BuildSummary |
291 | 292 |
292 func (a newBuildsFirst) Len() int { return len(a) } | 293 func (a newBuildsFirst) Len() int { return len(a) } |
293 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | 294 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
294 func (a newBuildsFirst) Less(i, j int) bool { | 295 func (a newBuildsFirst) Less(i, j int) bool { |
295 return a[i].PendingTime.Started.After(a[j].PendingTime.Started) | 296 return a[i].PendingTime.Started.After(a[j].PendingTime.Started) |
296 } | 297 } |
OLD | NEW |