Chromium Code Reviews| Index: dm/appengine/distributor/config.go |
| diff --git a/dm/appengine/distributor/config.go b/dm/appengine/distributor/config.go |
| index 50e69f46fff83c96d32a9424779f995d108c10b2..6c7a936d2611e0fc70c25e4b39a5c85930868735 100644 |
| --- a/dm/appengine/distributor/config.go |
| +++ b/dm/appengine/distributor/config.go |
| @@ -5,10 +5,15 @@ |
| package distributor |
| import ( |
| + "fmt" |
| + |
| "golang.org/x/net/context" |
| "github.com/golang/protobuf/proto" |
| + "github.com/luci/gae/service/info" |
| "github.com/luci/gae/service/taskqueue" |
| + "github.com/luci/luci-go/common/gcloud/pubsub" |
| + dm "github.com/luci/luci-go/dm/api/service/v1" |
| ) |
| // Config represents the configuration for a single instance of a given |
| @@ -36,3 +41,19 @@ func (cfg *Config) EnqueueTask(c context.Context, tsk *taskqueue.Task) error { |
| tsk.Path = handlerPath(cfg.Name) |
| return taskqueue.Get(c).Add(tsk, "") |
| } |
| + |
| +// PrepareTopic returns a pubsub topic that notifications should be sent to, and |
| +// is meant to be called from the D.Run method. |
| +// |
| +// It returns the full name of the topic and a token that will be used to route |
| +// PubSub messages back to the Distributor. The publisher to the topic must be |
| +// instructed to put the token into the 'auth_token' attribute of PubSub |
| +// messages. DM will know how to route such messages to D.HandleNotification. |
| +func (cfg *Config) PrepareTopic(c context.Context, eid *dm.Execution_ID) (topic pubsub.Topic, token string, err error) { |
| + topic = pubsub.NewTopic(info.Get(c).TrimmedAppID(), notifyTopicSuffix) |
|
Vadim Sh.
2016/09/20 00:24:26
consider caching the flag that this work has been
iannucci
2016/09/20 00:51:28
I think it will make sense to do this when DM even
|
| + if err := topic.Validate(); err != nil { |
| + panic(fmt.Errorf("failed to validate Topic %q: %s", topic, err)) |
| + } |
| + token, err = encodeAuthToken(c, eid, cfg.Name) |
| + return |
| +} |