Chromium Code Reviews| Index: appengine/cmd/dm/distributor/task_description.go |
| diff --git a/appengine/cmd/dm/distributor/task_description.go b/appengine/cmd/dm/distributor/task_description.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7a1dd1825df52a410237b4385819f7d062734562 |
| --- /dev/null |
| +++ b/appengine/cmd/dm/distributor/task_description.go |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2016 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package distributor |
| + |
| +import ( |
| + "github.com/luci/gae/service/info" |
| + dm "github.com/luci/luci-go/common/api/dm/service/v1" |
| + "github.com/luci/luci-go/common/gcloud/pubsub" |
| + "golang.org/x/net/context" |
| +) |
| + |
| +// NewTaskDescription builds a new *TaskDescription. |
| +// |
| +// It's intended for use by the DM core logic, and not for use by distributor |
| +// implementations. |
| +func NewTaskDescription(c context.Context, payload *dm.Quest_Desc, exAuth *dm.Execution_Auth, |
| + state PersistentState) *TaskDescription { |
| + return &TaskDescription{ |
| + c: c, |
| + payload: payload, |
| + executionAuth: exAuth, |
| + previousState: state, |
| + } |
| +} |
| + |
| +// TaskDescription is the parameters for PrepareTask. |
| +type TaskDescription struct { |
| + c context.Context |
| + payload *dm.Quest_Desc |
| + executionAuth *dm.Execution_Auth |
| + previousState PersistentState |
| +} |
| + |
| +// PrepareTopic returns the pubsub topic that notifications should be sent to. |
| +// |
| +// 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 (t *TaskDescription) PrepareTopic() (topic pubsub.Topic, token string, err error) { |
| + 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.
|
| + token, err = encodeAuthToken(t.c, t.executionAuth.Id, |
| + t.payload.DistributorConfigName) |
| + return |
| +} |
| + |
| +// PreviousState is the current PersistentState of the Attempt (e.g. the |
| +// PersistentState returned by the previous Execution). This will be empty |
| +// for the first Execution. |
| +func (t *TaskDescription) PreviousState() PersistentState { |
| + return t.previousState |
| +} |
| + |
| +// Payload is description of the job to run. |
| +func (t *TaskDescription) Payload() *dm.Quest_Desc { |
| + return t.payload.Clone() |
| +} |
| + |
| +// ExecutionAuth is the combined execution_id+activation token that the |
| +// execution must use to call ActivateExecution before making further API calls |
| +// into DM. |
| +func (t *TaskDescription) ExecutionAuth() *dm.Execution_Auth { |
| + ret := *t.executionAuth |
| + return &ret |
| +} |