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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/cmd/dm/distributor/tq_handler.go
diff --git a/appengine/cmd/dm/distributor/tq_handler.go b/appengine/cmd/dm/distributor/tq_handler.go
new file mode 100644
index 0000000000000000000000000000000000000000..8293c542621cc9b06476f4cf6c66bf083f09458b
--- /dev/null
+++ b/appengine/cmd/dm/distributor/tq_handler.go
@@ -0,0 +1,49 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package distributor
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+
+ "github.com/julienschmidt/httprouter"
+ "github.com/luci/luci-go/appengine/gaemiddleware"
+ "github.com/luci/luci-go/server/middleware"
+ "golang.org/x/net/context"
+)
+
+const handlerPattern = "/tq/distributor/:cfgName"
+
+func handlerPath(cfgName string) string {
+ return strings.Replace(handlerPattern, ":cfgName", url.QueryEscape(cfgName), 1)
+}
+
+// InstallHandlers installs the taskqueue callback handler.
+func InstallHandlers(r *httprouter.Router, base middleware.Base) {
+ r.POST(handlerPattern, base(
+ gaemiddleware.RequireTaskQueue("", taskqueHandler)))
+}
+
+func taskqueHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
+ defer r.Body.Close()
+
+ cfg, err := LoadConfiguration(c, p.ByName("cfgName"))
+ if err != nil {
+ http.Error(rw, "bad configuration name", http.StatusBadRequest)
+ return
+ }
+ dist, err := MakeDistributor(c, cfg)
+ if err != nil {
+ http.Error(rw, "bad distributor", http.StatusBadRequest)
+ return
+ }
+ err = dist.HandleTaskQueueTask(c, r)
+ if err != nil {
+ http.Error(rw, "failure to execute handler", http.StatusInternalServerError)
+ return
+ }
+ rw.WriteHeader(http.StatusOK)
+}

Powered by Google App Engine
This is Rietveld 408576698