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

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: gaemiddleware: add middleware func for WithProd 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
« no previous file with comments | « appengine/cmd/logdog_coordinator/vmuser/main.go ('k') | appengine/cmd/milo/buildbot/pubsub_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/milo/buildbot/pubsub.go
diff --git a/appengine/cmd/milo/buildbot/pubsub.go b/appengine/cmd/milo/buildbot/pubsub.go
index 0f883fa30c9d74c8f5a1d4c121a453adffdc3628..d4d88df1de90584a66e698b1d21beef076b26bdf 100644
--- a/appengine/cmd/milo/buildbot/pubsub.go
+++ b/appengine/cmd/milo/buildbot/pubsub.go
@@ -3,29 +3,28 @@
// that can be found in the LICENSE file.
package buildbot
import (
"bytes"
"compress/gzip"
"compress/zlib"
"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"
)
var (
// subName is the name of the pubsub subscription that milo is expecting.
// TODO(hinoka): This should be read from luci-config.
subName = "projects/luci-milo/subscriptions/buildbot-public"
)
type pubSubMessage struct {
@@ -111,22 +110,23 @@ func unmarshal(
bm.Builds = append(bm.Builds, build)
slave.RunningbuildsMap[build.Buildername] = append(
slave.RunningbuildsMap[build.Buildername], build.Number)
}
slave.Runningbuilds = nil
}
return bm.Builds, bm.Master, nil
}
// 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) {
+func PubSubHandler(ctx *router.Context) {
+ c, h, r := ctx.Context, ctx.Writer, ctx.Request
+
msg := pubSubSubscription{}
defer r.Body.Close()
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.
return
}
if msg.Subscription != subName {
« no previous file with comments | « appengine/cmd/logdog_coordinator/vmuser/main.go ('k') | appengine/cmd/milo/buildbot/pubsub_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698