OLD | NEW |
(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 } |
OLD | NEW |