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

Unified Diff: appengine/cmd/milo/buildbot/pubsub.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests Created 4 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 side-by-side diff with in-line comments
Download patch
Index: appengine/cmd/milo/buildbot/pubsub.go
diff --git a/appengine/cmd/milo/buildbot/pubsub.go b/appengine/cmd/milo/buildbot/pubsub.go
index 3dd09904647f2c09db8605c633b029571b59e1f0..612a0ce899d95fd9f41e1b51cf6874fbfcac687a 100644
--- a/appengine/cmd/milo/buildbot/pubsub.go
+++ b/appengine/cmd/milo/buildbot/pubsub.go
@@ -9,15 +9,14 @@ import (
"compress/gzip"
"encoding/base64"
"encoding/json"
- "net/http"
"time"
"github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/iotools"
log "github.com/luci/luci-go/common/logging"
+ "github.com/luci/luci-go/server/router"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
)
@@ -139,33 +138,37 @@ func unmarshal(
}
// PubSubHandler is a webhook that stores the builds coming in from pubsub.
-func PubSubHandler(
- c context.Context, h http.ResponseWriter, r *http.Request, p httprouter.Params) {
- msg := pubSubSubscription{}
+func PubSubHandler(ctx *router.Context) {
+ c, h, r := ctx.Context, ctx.Writer, ctx.Request
defer r.Body.Close()
+ msg := pubSubSubscription{}
dec := json.NewDecoder(r.Body)
if err := dec.Decode(&msg); err != nil {
log.WithError(err).Errorf(
c, "Could not decode message. %s", err)
h.WriteHeader(200) // This is a hard failure, we don't want PubSub to retry.
+ ctx.Abort()
return
}
if msg.Subscription != subName {
log.Errorf(
c, "Subscription name %s does not match %s", msg.Subscription, subName)
h.WriteHeader(200)
+ ctx.Abort()
return
}
bbMsg, err := msg.GetData()
if err != nil {
log.WithError(err).Errorf(c, "Could not decode message %s", err)
h.WriteHeader(200)
+ ctx.Abort()
return
}
builds, master, err := unmarshal(c, bbMsg)
if err != nil {
log.WithError(err).Errorf(c, "Could not unmarshal message %s", err)
h.WriteHeader(200)
+ ctx.Abort()
return
}
log.Infof(c, "There are %d builds and master %s", len(builds), master.Name)
@@ -177,6 +180,7 @@ func PubSubHandler(
if build.Master == "" {
log.Errorf(c, "Invalid message, missing master name")
h.WriteHeader(200)
+ ctx.Abort()
return
}
existingBuild := &buildbotBuild{
@@ -195,6 +199,7 @@ func PubSubHandler(
log.WithError(err).Errorf(c, "Could not save build in datastore %s", err)
// This is transient, we do want PubSub to retry.
h.WriteHeader(500)
+ ctx.Abort()
return
}
}
@@ -206,6 +211,7 @@ func PubSubHandler(
c, "Could not save master in datastore %s", err)
// This is transient, we do want PubSub to retry.
h.WriteHeader(500)
+ ctx.Abort()
return
}
}

Powered by Google App Engine
This is Rietveld 408576698