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

Side by Side Diff: appengine/cmd/milo/buildbot/console.go

Issue 2196453002: Milo: Console view prototype (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fixes Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package buildbot
6
7 import (
8 "fmt"
9 "strings"
10
11 "github.com/luci/gae/service/datastore"
12 "github.com/luci/luci-go/appengine/cmd/milo/resp"
13 "github.com/luci/luci-go/common/clock"
14 log "github.com/luci/luci-go/common/logging"
15 "github.com/luci/luci-go/common/sync/parallel"
16 "golang.org/x/net/context"
17 )
18
19 // getFullBuilds fetches all of the recent builds from the datastore.
20 func getFullBuilds(c context.Context, masterName, builderName string, finished b ool) ([]*buildbotBuild, error) {
21 // TODO(hinoka): Builder specific structs.
22 ds := datastore.Get(c)
23 q := datastore.NewQuery("buildbotBuild")
24 q = q.Eq("finished", finished)
25 q = q.Eq("master", masterName)
26 q = q.Eq("builder", builderName)
27 q = q.Limit(25) // TODO(hinoka): This should be adjustable
28 q = q.Order("-number")
29 q.Finalize()
30 buildbots := make([]*buildbotBuild, 0, 25)
31 err := ds.GetAll(q, &buildbots)
32 return buildbots, err
33 }
34
35 func GetConsoleBuilds(
36 c context.Context, builders []resp.BuilderRef, commits []string) (
37 [][]*resp.ConsoleBuild, error) {
nodir 2016/08/04 23:13:12 document what indexes in the return value mean
hinoka 2016/08/05 00:10:41 Done.
38
39 results := make([][]*resp.ConsoleBuild, len(commits))
40 for i := range results {
41 results[i] = make([]*resp.ConsoleBuild, len(builders))
42 }
43 // HACK(hinoka): This fetches 25 full builds and then filters them. Repl ace this
44 // with something more reasonable.
45 // This is kind of a hack but it's okay for now.
46 err := parallel.FanOutIn(func(taskC chan<- func() error) {
47 for i, builder := range builders {
48 i := i // How do scopes werk
49 f := strings.SplitN(builder.Name, "/", 2)
nodir 2016/08/04 23:13:13 i am not sure what f stands for
hinoka 2016/08/05 00:10:42 Done.
50 if len(f) != 2 {
51 taskC <- func() error {
52 return fmt.Errorf("%s is an invalid buil der name", builder.Name)
nodir 2016/08/04 23:13:12 builder var is captured, so there is a race you ne
hinoka 2016/08/05 00:10:41 Oh good catch
53 }
54 return
55 }
56 master := f[0]
57 builderName := f[1]
58 taskC <- func() error {
59 t1 := clock.Now(c)
60 builds, err := getFullBuilds(c, master, builderN ame, true)
61 if err != nil {
62 return err
63 }
64 t2 := clock.Now(c)
65 var currentStatus *resp.Status
66 for j, commit := range commits {
67 for _, build := range builds {
68 if build.Sourcestamp.Revision == commit {
nodir 2016/08/04 23:13:12 why does this have only one source stamp? a build
hinoka 2016/08/05 00:10:41 This is buildbot's own concept of sourcestamp, tha
69 results[j][i] = &resp.Co nsoleBuild{
nodir 2016/08/04 23:13:12 since there is no "break" in the end of this `if`,
hinoka 2016/08/05 00:10:41 I think we should pick the latest one (This code w
70 Link: &resp.Link {
71 Label: s trings.Join(build.Text, " "),
72 URL: fmt .Sprintf(
73 "/buildbot/%s/%s/%d", master, builderName, build.Number),
74 },
75 Status: build.to Status(),
76 }
77 currentStatus = &results [j][i].Status
78 }
79 }
80 if currentStatus != nil && results[j][i] == nil {
81 results[j][i] = &resp.ConsoleBui ld{Status: *currentStatus}
82 }
83 }
84 log.Debugf(c,
85 "Builder %s took %s to query, %s to comp ute.", builderName,
86 t2.Sub(t1), clock.Since(c, t2))
87 return nil
88 }
89 }
90 })
91 return results, err
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698