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

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 comments 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
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 "github.com/luci/gae/service/info"
9 dm "github.com/luci/luci-go/common/api/dm/service/v1"
10 "github.com/luci/luci-go/common/gcloud/pubsub"
11 "golang.org/x/net/context"
12 )
13
14 // NewTaskDescription builds a new *TaskDescription.
15 //
16 // It's intended for use by the DM core logic, and not for use by distributor
17 // implementations.
18 func NewTaskDescription(c context.Context, payload *dm.Quest_Desc, exAuth *dm.Ex ecution_Auth,
19 state PersistentState) *TaskDescription {
20 return &TaskDescription{
21 c: c,
22 payload: payload,
23 executionAuth: exAuth,
24 previousState: state,
25 }
26 }
27
28 // TaskDescription is the parameters for PrepareTask.
29 type TaskDescription struct {
30 c context.Context
31 payload *dm.Quest_Desc
32 executionAuth *dm.Execution_Auth
33 previousState PersistentState
34 }
35
36 // PrepareTopic returns the pubsub topic that notifications should be sent to.
37 //
38 // It returns the full name of the topic and a token that will be used to route
39 // PubSub messages back to the Distributor. The publisher to the topic must be
40 // instructed to put the token into the 'auth_token' attribute of PubSub
41 // messages. DM will know how to route such messages to D.HandleNotification.
42 func (t *TaskDescription) PrepareTopic() (topic pubsub.Topic, token string, err error) {
43 topic = pubsub.NewTopic(info.Get(t.c).TrimmedAppID(), notifyTopicSuffix)
dnj (Google) 2016/06/16 16:57:22 It's not a bad idea to validate the topic here jus
iannucci 2016/06/18 01:35:41 Done.
44 token, err = encodeAuthToken(t.c, t.executionAuth.Id,
45 t.payload.DistributorConfigName)
46 return
47 }
48
49 // PreviousState is the current PersistentState of the Attempt (e.g. the
50 // PersistentState returned by the previous Execution). This will be empty
51 // for the first Execution.
52 func (t *TaskDescription) PreviousState() PersistentState {
53 return t.previousState
54 }
55
56 // Payload is description of the job to run.
57 func (t *TaskDescription) Payload() *dm.Quest_Desc {
58 return t.payload.Clone()
59 }
60
61 // ExecutionAuth is the combined execution_id+activation token that the
62 // execution must use to call ActivateExecution before making further API calls
63 // into DM.
64 func (t *TaskDescription) ExecutionAuth() *dm.Execution_Auth {
65 ret := *t.executionAuth
66 return &ret
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698