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

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

Issue 2406163003: Milo: Clean up builds that are no longer current. (Closed)
Patch Set: Clean up debug output Created 4 years, 2 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 | « no previous file | milo/appengine/buildbot/pubsub_test.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 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "compress/zlib" 10 "compress/zlib"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Extract OS and OS Family 173 // Extract OS and OS Family
174 if v, ok := hostInfo["os family"]; ok { 174 if v, ok := hostInfo["os family"]; ok {
175 family = v 175 family = v
176 } 176 }
177 if v, ok := hostInfo["os version"]; ok { 177 if v, ok := hostInfo["os version"]; ok {
178 version = v 178 version = v
179 } 179 }
180 return 180 return
181 } 181 }
182 182
183 // Marks a build as finished and expired.
184 func expireBuild(c context.Context, b *buildbotBuild) error {
185 finished := float64(clock.Now(c).Unix())
186 if b.TimeStamp != nil {
187 finished = float64(*b.TimeStamp)
188 }
189 results := int(2)
190 b.Times[1] = &finished
191 b.Finished = true
192 b.Results = &results
193 return ds.Put(c, b)
194 }
195
183 // PubSubHandler is a webhook that stores the builds coming in from pubsub. 196 // PubSubHandler is a webhook that stores the builds coming in from pubsub.
184 func PubSubHandler(ctx *router.Context) { 197 func PubSubHandler(ctx *router.Context) {
185 c, h, r := ctx.Context, ctx.Writer, ctx.Request 198 c, h, r := ctx.Context, ctx.Writer, ctx.Request
186 199
187 msg := pubSubSubscription{} 200 msg := pubSubSubscription{}
188 defer r.Body.Close() 201 defer r.Body.Close()
189 dec := json.NewDecoder(r.Body) 202 dec := json.NewDecoder(r.Body)
190 if err := dec.Decode(&msg); err != nil { 203 if err := dec.Decode(&msg); err != nil {
191 logging.WithError(err).Errorf( 204 logging.WithError(err).Errorf(
192 c, "Could not decode message. %s", err) 205 c, "Could not decode message. %s", err)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if buildExists { 289 if buildExists {
277 buildCounter.Add( 290 buildCounter.Add(
278 c, 1, false, build.Master, build.Buildername, bu ild.Finished, "Replaced") 291 c, 1, false, build.Master, build.Buildername, bu ild.Finished, "Replaced")
279 } else { 292 } else {
280 buildCounter.Add( 293 buildCounter.Add(
281 c, 1, false, build.Master, build.Buildername, bu ild.Finished, "New") 294 c, 1, false, build.Master, build.Buildername, bu ild.Finished, "New")
282 } 295 }
283 296
284 } 297 }
285 if master != nil { 298 if master != nil {
299 // Store the master json into the datastore.
286 err = putDSMasterJSON(c, master, internal) 300 err = putDSMasterJSON(c, master, internal)
287 if err != nil { 301 if err != nil {
288 logging.WithError(err).Errorf( 302 logging.WithError(err).Errorf(
289 c, "Could not save master in datastore %s", err) 303 c, "Could not save master in datastore %s", err)
290 // This is transient, we do want PubSub to retry. 304 // This is transient, we do want PubSub to retry.
291 h.WriteHeader(500) 305 h.WriteHeader(500)
292 return 306 return
293 } 307 }
308
309 // Extract current builds data out of the master json, and use i t to
estaab 2016/10/20 03:30:39 This function is pretty long by this point. Is the
hinoka 2016/10/26 01:28:04 Done.
310 // clean up expired builds.
311 q := ds.NewQuery("buildbotBuild").
312 Eq("finished", false).
313 Eq("master", master.Name)
314 builds := []*buildbotBuild{}
315 err := ds.GetAll(c, q, &builds)
316 if err != nil {
317 logging.WithError(err).Errorf(c, "Could not load current builds from master %s",
318 master.Name)
319 h.WriteHeader(500)
320 return
321 }
322 for _, b := range builds {
323 builder, ok := master.Builders[b.Buildername]
324 if !ok {
325 // Mark this build due to builder being removed.
326 logging.Infof(c, "Expiring %s/%s/%d due to build er being removed",
327 master.Name, b.Buildername, b.Number)
328 err = expireBuild(c, b)
329 if err != nil {
330 logging.WithError(err).Errorf(c, "Could not expire build")
331 h.WriteHeader(500)
332 return
333 }
334 }
335
336 found := false
337 for _, bnum := range builder.CurrentBuilds {
338 if b.Number == bnum {
339 found = true
340 break
341 }
342 }
343 if !found {
344 // Mark this build due to build not current anym ore.
345 logging.Infof(c, "Expiring %s/%s/%d due to build not current",
346 master.Name, b.Buildername, b.Number)
347 err = expireBuild(c, b)
348 if err != nil {
349 logging.WithError(err).Errorf(c, "Could not expire build")
350 h.WriteHeader(500)
351 return
352 }
353 }
354 }
294 } 355 }
295 h.WriteHeader(200) 356 h.WriteHeader(200)
296 } 357 }
OLDNEW
« no previous file with comments | « no previous file | milo/appengine/buildbot/pubsub_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698