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

Unified 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 side-by-side diff with in-line comments
Download patch
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..76d9e5d5bf0759d93937fe659e379a51ebdfbb06
--- /dev/null
+++ b/appengine/cmd/dm/distributor/task_description.go
@@ -0,0 +1,71 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package distributor
+
+import (
+ dm "github.com/luci/luci-go/common/api/dm/service/v1"
+ "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, token string, err error) {
+ topic = pubsubTopic(t.c)
+ 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 {
+ 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.
+ meta := *ret.Meta
+ retry := *meta.Retry
+
+ meta.Retry = &retry
+ ret.Meta = &meta
+ return &ret
+}
+
+// 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
+}

Powered by Google App Engine
This is Rietveld 408576698