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

Unified Diff: appengine/cmd/dm/model/quest.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/model/quest.go
diff --git a/appengine/cmd/dm/model/quest.go b/appengine/cmd/dm/model/quest.go
index d16f0a97e418bd57d0cc2315ae4391a5bfa36134..318704e230516522a7261770c22975060ffd7eb1 100644
--- a/appengine/cmd/dm/model/quest.go
+++ b/appengine/cmd/dm/model/quest.go
@@ -5,59 +5,23 @@
package model
import (
- "crypto/sha256"
- "encoding/base64"
- "fmt"
"time"
- "github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/common/clock"
google_pb "github.com/luci/luci-go/common/proto/google"
- "github.com/luci/luci-go/common/api/dm/service/v1"
- "github.com/luci/luci-go/common/api/template"
-)
-
-var (
- // QuestIDLength is the number of encoded bytes to use. It removes the
- // single padding character.
- QuestIDLength = base64.URLEncoding.EncodedLen(sha256.Size) - 1
-)
-
-const (
- // payloadMaxLength is the maximum size of the Quest Desc
- payloadMaxLength = 256 * 1024
+ dm "github.com/luci/luci-go/common/api/dm/service/v1"
)
// NewQuest builds a new Quest object with a correct ID given the current
// contents of the Quest_Desc. It returns an error if the Desc is invalid.
//
-// This will also compactify the inner json Desc as a side effect.
-func NewQuest(c context.Context, desc *dm.Quest_Desc) (ret *Quest, err error) {
- if len(desc.JsonPayload) > payloadMaxLength {
- return nil, fmt.Errorf("quest payload is too large: %d > %d",
- len(desc.JsonPayload), payloadMaxLength)
- }
- desc.JsonPayload, err = template.NormalizeJSON(desc.JsonPayload, true)
- if err != nil {
- return
- }
-
- data, err := proto.Marshal(desc)
- if err != nil {
- panic(err)
- }
- h := sha256.Sum256(data)
-
- ret = &Quest{
- ID: base64.URLEncoding.EncodeToString(h[:])[:QuestIDLength],
- Desc: *desc,
- Created: clock.Now(c).UTC(),
- }
- return
+// Desc must already be Normalize()'d
+func NewQuest(c context.Context, desc *dm.Quest_Desc) *Quest {
dnj (Google) 2016/06/09 18:00:56 It might not be a bad idea to omit "c" here and su
iannucci 2016/06/15 00:46:01 I think I like the context better: the fact that w
+ return &Quest{ID: desc.QuestID(), Desc: *desc, Created: clock.Now(c).UTC()}
}
// Quest is the model for a job-to-run. Its questPayload should fully

Powered by Google App Engine
This is Rietveld 408576698