| OLD | NEW |
| 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 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "net/http" | 10 "net/http" |
| 11 "strconv" | 11 "strconv" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "github.com/julienschmidt/httprouter" | |
| 15 "github.com/luci/luci-go/appengine/tumble" | 14 "github.com/luci/luci-go/appengine/tumble" |
| 16 "github.com/luci/luci-go/common/api/dm/service/v1" | 15 "github.com/luci/luci-go/common/api/dm/service/v1" |
| 17 "github.com/luci/luci-go/common/logging" | 16 "github.com/luci/luci-go/common/logging" |
| 17 "github.com/luci/luci-go/server/router" |
| 18 "github.com/luci/luci-go/server/tokens" | 18 "github.com/luci/luci-go/server/tokens" |
| 19 "golang.org/x/net/context" | 19 "golang.org/x/net/context" |
| 20 ) | 20 ) |
| 21 | 21 |
| 22 const notifyTopicSuffix = "dm-distributor-notify" | 22 const notifyTopicSuffix = "dm-distributor-notify" |
| 23 | 23 |
| 24 // PubsubReciever is the HTTP handler that processes incoming pubsub events | 24 // PubsubReceiver is the HTTP handler that processes incoming pubsub events |
| 25 // delivered to topics prepared with TaskDescription.PrepareTopic, and routes | 25 // delivered to topics prepared with TaskDescription.PrepareTopic, and routes |
| 26 // them to the appropriate distributor implementation's HandleNotification | 26 // them to the appropriate distributor implementation's HandleNotification |
| 27 // method. | 27 // method. |
| 28 // | 28 // |
| 29 // It requires that a Registry be installed in c via WithRegistry. | 29 // It requires that a Registry be installed in c via WithRegistry. |
| 30 func PubsubReciever(c context.Context, rw http.ResponseWriter, r *http.Request,
p httprouter.Params) { | 30 func PubsubReceiver(ctx *router.Context) { |
| 31 » c, rw, r := ctx.Context, ctx.Writer, ctx.Request |
| 31 defer r.Body.Close() | 32 defer r.Body.Close() |
| 32 | 33 |
| 33 type PubsubMessage struct { | 34 type PubsubMessage struct { |
| 34 Attributes map[string]string `json:"attributes"` | 35 Attributes map[string]string `json:"attributes"` |
| 35 Data []byte `json:"data"` | 36 Data []byte `json:"data"` |
| 36 MessageID string `json:"message_id"` | 37 MessageID string `json:"message_id"` |
| 37 } | 38 } |
| 38 type PubsubPushMessage struct { | 39 type PubsubPushMessage struct { |
| 39 Message PubsubMessage `json:"message"` | 40 Message PubsubMessage `json:"message"` |
| 40 Subscription string `json:"subscription"` | 41 Subscription string `json:"subscription"` |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 113 } |
| 113 eid = dm.NewExecutionID(quest, uint32(attemptNum), uint32(executionNum)) | 114 eid = dm.NewExecutionID(quest, uint32(attemptNum), uint32(executionNum)) |
| 114 | 115 |
| 115 cfgName, ok := items["cfgName"] | 116 cfgName, ok := items["cfgName"] |
| 116 if !ok { | 117 if !ok { |
| 117 err = fmt.Errorf("missing config name") | 118 err = fmt.Errorf("missing config name") |
| 118 } | 119 } |
| 119 | 120 |
| 120 return | 121 return |
| 121 } | 122 } |
| OLD | NEW |