summaryrefslogtreecommitdiff
path: root/misc/dashboard/app/build/build.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-03-04 21:27:36 +0100
committerMichael Stapelberg <michael@stapelberg.de>2013-03-04 21:27:36 +0100
commit04b08da9af0c450d645ab7389d1467308cfc2db8 (patch)
treedb247935fa4f2f94408edc3acd5d0d4f997aa0d8 /misc/dashboard/app/build/build.go
parent917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff)
downloadgolang-upstream/1.1_hg20130304.tar.gz
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'misc/dashboard/app/build/build.go')
-rw-r--r--misc/dashboard/app/build/build.go46
1 files changed, 33 insertions, 13 deletions
diff --git a/misc/dashboard/app/build/build.go b/misc/dashboard/app/build/build.go
index c49fa8bb2..e0c0f0048 100644
--- a/misc/dashboard/app/build/build.go
+++ b/misc/dashboard/app/build/build.go
@@ -49,6 +49,10 @@ func (p *Package) LastCommit(c appengine.Context) (*Commit, error) {
Order("-Time").
Limit(1).
GetAll(c, &commits)
+ if _, ok := err.(*datastore.ErrFieldMismatch); ok {
+ // Some fields have been removed, so it's okay to ignore this error.
+ err = nil
+ }
if err != nil {
return nil, err
}
@@ -65,6 +69,10 @@ func GetPackage(c appengine.Context, path string) (*Package, error) {
if err == datastore.ErrNoSuchEntity {
return nil, fmt.Errorf("package %q not found", path)
}
+ if _, ok := err.(*datastore.ErrFieldMismatch); ok {
+ // Some fields have been removed, so it's okay to ignore this error.
+ err = nil
+ }
return p, err
}
@@ -111,19 +119,35 @@ func (c *Commit) Valid() error {
return nil
}
+// each result line is approx 105 bytes. This constant is a tradeoff between
+// build history and the AppEngine datastore limit of 1mb.
+const maxResults = 1000
+
// AddResult adds the denormalized Reuslt data to the Commit's Result field.
// It must be called from inside a datastore transaction.
func (com *Commit) AddResult(c appengine.Context, r *Result) error {
if err := datastore.Get(c, com.Key(c), com); err != nil {
return fmt.Errorf("getting Commit: %v", err)
}
- com.ResultData = append(com.ResultData, r.Data())
+ com.ResultData = trim(append(com.ResultData, r.Data()), maxResults)
if _, err := datastore.Put(c, com.Key(c), com); err != nil {
return fmt.Errorf("putting Commit: %v", err)
}
return nil
}
+func trim(s []string, n int) []string {
+ l := min(len(s), n)
+ return s[len(s)-l:]
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
// Result returns the build Result for this Commit for the given builder/goHash.
func (c *Commit) Result(builder, goHash string) *Result {
for _, r := range c.ResultData {
@@ -160,20 +184,11 @@ func partsToHash(c *Commit, p []string) *Result {
}
}
-// OK returns the Commit's build state for a specific builder and goHash.
-func (c *Commit) OK(builder, goHash string) (ok, present bool) {
- r := c.Result(builder, goHash)
- if r == nil {
- return false, false
- }
- return r.OK, true
-}
-
// A Result describes a build result for a Commit on an OS/architecture.
//
// Each Result entity is a descendant of its associated Commit entity.
type Result struct {
- Builder string // "arch-os[-note]"
+ Builder string // "os-arch[-note]"
Hash string
PackagePath string // (empty for Go commits)
@@ -184,7 +199,7 @@ type Result struct {
Log string `datastore:"-"` // for JSON unmarshaling only
LogHash string `datastore:",noindex"` // Key to the Log record.
- RunTime int64 // time to build+test in nanoseconds
+ RunTime int64 // time to build+test in nanoseconds
}
func (r *Result) Key(c appengine.Context) *datastore.Key {
@@ -297,7 +312,12 @@ func Packages(c appengine.Context, kind string) ([]*Package, error) {
q := datastore.NewQuery("Package").Filter("Kind=", kind)
for t := q.Run(c); ; {
pkg := new(Package)
- if _, err := t.Next(pkg); err == datastore.Done {
+ _, err := t.Next(pkg)
+ if _, ok := err.(*datastore.ErrFieldMismatch); ok {
+ // Some fields have been removed, so it's okay to ignore this error.
+ err = nil
+ }
+ if err == datastore.Done {
break
} else if err != nil {
return nil, err