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

Side by Side Diff: appengine/cmd/dm/distributor/task_description.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file Created 4 years, 6 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
« no previous file with comments | « appengine/cmd/dm/distributor/registry.go ('k') | appengine/cmd/dm/distributor/test_registry.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package distributor
6
7 import (
8 "fmt"
9
10 "github.com/golang/protobuf/proto"
11 "github.com/luci/gae/service/info"
12 dm "github.com/luci/luci-go/common/api/dm/service/v1"
13 "github.com/luci/luci-go/common/gcloud/pubsub"
14 "golang.org/x/net/context"
15 )
16
17 // NewTaskDescription builds a new *TaskDescription.
18 //
19 // It's intended for use by the DM core logic, and not for use by distributor
20 // implementations.
21 func NewTaskDescription(c context.Context, payload *dm.Quest_Desc, exAuth *dm.Ex ecution_Auth,
22 state PersistentState) *TaskDescription {
23 return &TaskDescription{
24 c: c,
25 payload: payload,
26 executionAuth: exAuth,
27 previousState: state,
28 }
29 }
30
31 // TaskDescription is the parameters for PrepareTask.
32 type TaskDescription struct {
33 c context.Context
34 payload *dm.Quest_Desc
35 executionAuth *dm.Execution_Auth
36 previousState PersistentState
37 }
38
39 // PrepareTopic returns the pubsub topic that notifications should be sent to.
40 //
41 // It returns the full name of the topic and a token that will be used to route
42 // PubSub messages back to the Distributor. The publisher to the topic must be
43 // instructed to put the token into the 'auth_token' attribute of PubSub
44 // messages. DM will know how to route such messages to D.HandleNotification.
45 func (t *TaskDescription) PrepareTopic() (topic pubsub.Topic, token string, err error) {
46 topic = pubsub.NewTopic(info.Get(t.c).TrimmedAppID(), notifyTopicSuffix)
47 if err := topic.Validate(); err != nil {
48 panic(fmt.Errorf("failed to validate Topic %q: %s", topic, err))
49 }
50 token, err = encodeAuthToken(t.c, t.executionAuth.Id,
51 t.payload.DistributorConfigName)
52 return
53 }
54
55 // PreviousState is the current PersistentState of the Attempt (e.g. the
56 // PersistentState returned by the previous Execution). This will be empty
57 // for the first Execution.
58 func (t *TaskDescription) PreviousState() PersistentState {
59 return t.previousState
60 }
61
62 // Payload is description of the job to run.
63 func (t *TaskDescription) Payload() *dm.Quest_Desc {
64 return proto.Clone(t.payload).(*dm.Quest_Desc)
65 }
66
67 // ExecutionAuth is the combined execution_id+activation token that the
68 // execution must use to call ActivateExecution before making further API calls
69 // into DM.
70 func (t *TaskDescription) ExecutionAuth() *dm.Execution_Auth {
71 ret := *t.executionAuth
72 return &ret
73 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/distributor/registry.go ('k') | appengine/cmd/dm/distributor/test_registry.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698