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

Unified Diff: dm/appengine/distributor/config.go

Issue 2347973003: Refactor distributor API so that methods always get the Quest_Desc too. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | dm/appengine/distributor/distributor.go » ('j') | dm/appengine/distributor/distributor.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+}
« no previous file with comments | « no previous file | dm/appengine/distributor/distributor.go » ('j') | dm/appengine/distributor/distributor.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698