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

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: work in progress Created 4 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // 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/gaemiddleware"
14 "github.com/luci/luci-go/server/middleware"
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 // InstallHandlers installs the taskqueue callback handler.
25 func InstallHandlers(r *httprouter.Router, base middleware.Base) {
26 r.POST(handlerPattern, base(
27 gaemiddleware.RequireTaskQueue("", taskqueHandler)))
28 }
29
30 func taskqueHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
31 defer r.Body.Close()
32
33 cfg, err := LoadConfiguration(c, p.ByName("cfgName"))
34 if err != nil {
35 http.Error(rw, "bad configuration name", http.StatusBadRequest)
36 return
37 }
38 dist, err := MakeDistributor(c, cfg)
39 if err != nil {
40 http.Error(rw, "bad distributor", http.StatusBadRequest)
41 return
42 }
43 err = dist.HandleTaskQueueTask(c, r)
44 if err != nil {
45 http.Error(rw, "failure to execute handler", http.StatusInternal ServerError)
46 return
47 }
48 rw.WriteHeader(http.StatusOK)
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698