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

Side by Side Diff: appengine/cmd/dm/distributor/tq_handler.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file 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/test_registry.go ('k') | appengine/cmd/dm/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package distributor
6
7 import (
8 "net/http"
9 "net/url"
10 "strings"
11
12 "github.com/julienschmidt/httprouter"
13 "github.com/luci/luci-go/appengine/tumble"
14 "github.com/luci/luci-go/common/logging"
15 "golang.org/x/net/context"
16 )
17
18 const handlerPattern = "/tq/distributor/:cfgName"
19
20 func handlerPath(cfgName string) string {
21 return strings.Replace(handlerPattern, ":cfgName", url.QueryEscape(cfgNa me), 1)
22 }
23
24 // TaskQueueHandler is the http handler that routes taskqueue tasks made with
25 // Config.EnqueueTask to a distributor's HandleTaskQueueTask method.
26 //
27 // This requires that c already have a Registry installed via the WithRegistry
28 // method.
29 func TaskQueueHandler(c context.Context, rw http.ResponseWriter, r *http.Request , p httprouter.Params) {
30 defer r.Body.Close()
31
32 cfgName := p.ByName("cfgName")
33 dist, _, err := GetRegistry(c).MakeDistributor(c, cfgName)
34 if err != nil {
35 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, "Failed t o make distributor")
36 http.Error(rw, "bad distributor", http.StatusBadRequest)
37 return
38 }
39 notifications, err := dist.HandleTaskQueueTask(r)
40 if err != nil {
41 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, "Failed t o handle taskqueue task")
42 http.Error(rw, "failure to execute handler", http.StatusInternal ServerError)
43 return
44 }
45 if len(notifications) > 0 {
46 muts := make([]tumble.Mutation, 0, len(notifications))
47 for _, notify := range notifications {
48 if notify != nil {
49 muts = append(muts, &NotifyExecution{cfgName, no tify})
50 }
51 }
52 err = tumble.AddToJournal(c, muts...)
53 if err != nil {
54 logging.Fields{"error": err, "cfg": cfgName}.Errorf(c, " Failed to handle notifications")
55 http.Error(rw, "failure to handle notifications", http.S tatusInternalServerError)
56 return
57 }
58 }
59 rw.WriteHeader(http.StatusOK)
60 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/distributor/test_registry.go ('k') | appengine/cmd/dm/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698