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

Side by Side Diff: appengine/cmd/dm/distributor/tq_handler.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 unified diff | Download patch
« no previous file with comments | « appengine/cmd/dm/distributor/pubsub.go ('k') | appengine/cmd/dm/frontend/init.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 distributor 5 package distributor
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 "net/url" 9 "net/url"
10 "strings" 10 "strings"
11 11
12 "github.com/julienschmidt/httprouter"
13 "github.com/luci/luci-go/appengine/tumble" 12 "github.com/luci/luci-go/appengine/tumble"
14 "github.com/luci/luci-go/common/logging" 13 "github.com/luci/luci-go/common/logging"
15 » "golang.org/x/net/context" 14 » "github.com/luci/luci-go/server/router"
16 ) 15 )
17 16
18 const handlerPattern = "/tq/distributor/:cfgName" 17 const handlerPattern = "/tq/distributor/:cfgName"
19 18
20 func handlerPath(cfgName string) string { 19 func handlerPath(cfgName string) string {
21 return strings.Replace(handlerPattern, ":cfgName", url.QueryEscape(cfgNa me), 1) 20 return strings.Replace(handlerPattern, ":cfgName", url.QueryEscape(cfgNa me), 1)
22 } 21 }
23 22
24 // TaskQueueHandler is the http handler that routes taskqueue tasks made with 23 // TaskQueueHandler is the http handler that routes taskqueue tasks made with
25 // Config.EnqueueTask to a distributor's HandleTaskQueueTask method. 24 // Config.EnqueueTask to a distributor's HandleTaskQueueTask method.
26 // 25 //
27 // This requires that c already have a Registry installed via the WithRegistry 26 // This requires that ctx.Context already have a Registry installed via the
28 // method. 27 // WithRegistry method.
29 func TaskQueueHandler(c context.Context, rw http.ResponseWriter, r *http.Request , p httprouter.Params) { 28 func TaskQueueHandler(ctx *router.Context) {
29 » c, rw, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params
30 defer r.Body.Close() 30 defer r.Body.Close()
31 31
32 cfgName := p.ByName("cfgName") 32 cfgName := p.ByName("cfgName")
33 dist, _, err := GetRegistry(c).MakeDistributor(c, cfgName) 33 dist, _, err := GetRegistry(c).MakeDistributor(c, cfgName)
34 if err != nil { 34 if err != nil {
35 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, "Failed t o make distributor") 35 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, "Failed t o make distributor")
36 http.Error(rw, "bad distributor", http.StatusBadRequest) 36 http.Error(rw, "bad distributor", http.StatusBadRequest)
37 return 37 return
38 } 38 }
39 notifications, err := dist.HandleTaskQueueTask(r) 39 notifications, err := dist.HandleTaskQueueTask(r)
(...skipping 11 matching lines...) Expand all
51 } 51 }
52 err = tumble.AddToJournal(c, muts...) 52 err = tumble.AddToJournal(c, muts...)
53 if err != nil { 53 if err != nil {
54 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, " Failed to handle notifications") 54 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, " Failed to handle notifications")
55 http.Error(rw, "failure to handle notifications", http.S tatusInternalServerError) 55 http.Error(rw, "failure to handle notifications", http.S tatusInternalServerError)
56 return 56 return
57 } 57 }
58 } 58 }
59 rw.WriteHeader(http.StatusOK) 59 rw.WriteHeader(http.StatusOK)
60 } 60 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/distributor/pubsub.go ('k') | appengine/cmd/dm/frontend/init.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698