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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "fmt"
9
8 "golang.org/x/net/context" 10 "golang.org/x/net/context"
9 11
10 "github.com/golang/protobuf/proto" 12 "github.com/golang/protobuf/proto"
13 "github.com/luci/gae/service/info"
11 "github.com/luci/gae/service/taskqueue" 14 "github.com/luci/gae/service/taskqueue"
15 "github.com/luci/luci-go/common/gcloud/pubsub"
16 dm "github.com/luci/luci-go/dm/api/service/v1"
12 ) 17 )
13 18
14 // Config represents the configuration for a single instance of a given 19 // Config represents the configuration for a single instance of a given
15 // distributor implementation at a given point in time (e.g. version). 20 // distributor implementation at a given point in time (e.g. version).
16 type Config struct { 21 type Config struct {
17 // DMHost is the host for the DM API. This may be used by the distributo r 22 // DMHost is the host for the DM API. This may be used by the distributo r
18 // implementation to pass to jobs so that they can call back into DM's a pi. 23 // implementation to pass to jobs so that they can call back into DM's a pi.
19 DMHost string 24 DMHost string
20 25
21 // Name is the name of this distributor configuration. This is always th e 26 // Name is the name of this distributor configuration. This is always th e
22 // fully-resolved name of the configuration (i.e. aliases are dereferenc ed). 27 // fully-resolved name of the configuration (i.e. aliases are dereferenc ed).
23 Name string 28 Name string
24 29
25 // Version is the version of the distributor configuration retrieved fro m 30 // Version is the version of the distributor configuration retrieved fro m
26 // luci-config. 31 // luci-config.
27 Version string 32 Version string
28 33
29 // Content is the actual parsed implementation-specific configuration. 34 // Content is the actual parsed implementation-specific configuration.
30 Content proto.Message 35 Content proto.Message
31 } 36 }
32 37
33 // EnqueueTask allows a Distributor to enqueue a TaskQueue task that will be 38 // EnqueueTask allows a Distributor to enqueue a TaskQueue task that will be
34 // handled by the Distributor's HandleTaskQueueTask method. 39 // handled by the Distributor's HandleTaskQueueTask method.
35 func (cfg *Config) EnqueueTask(c context.Context, tsk *taskqueue.Task) error { 40 func (cfg *Config) EnqueueTask(c context.Context, tsk *taskqueue.Task) error {
36 tsk.Path = handlerPath(cfg.Name) 41 tsk.Path = handlerPath(cfg.Name)
37 return taskqueue.Get(c).Add(tsk, "") 42 return taskqueue.Get(c).Add(tsk, "")
38 } 43 }
44
45 // PrepareTopic returns a pubsub topic that notifications should be sent to, and
46 // is meant to be called from the D.Run method.
47 //
48 // It returns the full name of the topic and a token that will be used to route
49 // PubSub messages back to the Distributor. The publisher to the topic must be
50 // instructed to put the token into the 'auth_token' attribute of PubSub
51 // messages. DM will know how to route such messages to D.HandleNotification.
52 func (cfg *Config) PrepareTopic(c context.Context, eid *dm.Execution_ID) (topic pubsub.Topic, token string, err error) {
53 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
54 if err := topic.Validate(); err != nil {
55 panic(fmt.Errorf("failed to validate Topic %q: %s", topic, err))
56 }
57 token, err = encodeAuthToken(c, eid, cfg.Name)
58 return
59 }
OLDNEW
« 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