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

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: self review 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 Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package distributor
6
7 import (
8 dm "github.com/luci/luci-go/common/api/dm/service/v1"
9 "golang.org/x/net/context"
10 )
11
12 // NewTaskDescription builds a new *TaskDescription.
13 //
14 // It's intended for use by the DM core logic, and not for use by distributor
15 // implementations.
16 func NewTaskDescription(c context.Context, payload *dm.Quest_Desc, exAuth *dm.Ex ecution_Auth,
17 state PersistentState) *TaskDescription {
18 return &TaskDescription{
19 c: c,
20 payload: payload,
21 executionAuth: exAuth,
22 previousState: state,
23 }
24 }
25
26 // TaskDescription is the parameters for PrepareTask.
27 type TaskDescription struct {
28 c context.Context
29 payload *dm.Quest_Desc
30 executionAuth *dm.Execution_Auth
31 previousState PersistentState
32 }
33
34 // PrepareTopic returns the pubsub topic that notifications should be sent to.
35 //
36 // It returns the full name of the topic and a token that will be used to route
37 // PubSub messages back to the Distributor. The publisher to the topic must be
38 // instructed to put the token into the 'auth_token' attribute of PubSub
39 // messages. DM will know how to route such messages to D.HandleNotification.
40 func (t *TaskDescription) PrepareTopic() (topic, token string, err error) {
41 topic = pubsubTopic(t.c)
42 token, err = encodeAuthToken(t.c, t.executionAuth.Id,
43 t.payload.DistributorConfigName)
44 return
45 }
46
47 // PreviousState is the current PersistentState of the Attempt (e.g. the
48 // PersistentState returned by the previous Execution). This will be empty
49 // for the first Execution.
50 func (t *TaskDescription) PreviousState() PersistentState {
51 return t.previousState
52 }
53
54 // Payload is description of the job to run.
55 func (t *TaskDescription) Payload() *dm.Quest_Desc {
56 ret := *t.payload
dnj (Google) 2016/06/09 18:00:56 I think you should build "clone" into "Quest_Desc"
iannucci 2016/06/15 00:46:00 yeah that's a better idea. I was tired :P. Done.
57 meta := *ret.Meta
58 retry := *meta.Retry
59
60 meta.Retry = &retry
61 ret.Meta = &meta
62 return &ret
63 }
64
65 // ExecutionAuth is the combined execution_id+activation token that the
66 // execution must use to call ActivateExecution before making further API calls
67 // into DM.
68 func (t *TaskDescription) ExecutionAuth() *dm.Execution_Auth {
69 ret := *t.executionAuth
70 return &ret
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698