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

Side by Side Diff: appengine/cmd/dm/mutate/merge_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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package mutate 5 package mutate
6 6
7 import ( 7 import (
8 "github.com/luci/gae/service/datastore" 8 "github.com/luci/gae/service/datastore"
9 "github.com/luci/luci-go/appengine/cmd/dm/model" 9 "github.com/luci/luci-go/appengine/cmd/dm/model"
10 "github.com/luci/luci-go/appengine/tumble" 10 "github.com/luci/luci-go/appengine/tumble"
11 "github.com/luci/luci-go/common/logging" 11 "github.com/luci/luci-go/common/logging"
12 "golang.org/x/net/context" 12 "golang.org/x/net/context"
13 ) 13 )
14 14
15 // MergeQuest ensures that the given Quest exists and contains the merged 15 // MergeQuest ensures that the given Quest exists and contains the merged
16 // set of BuiltBy entries. 16 // set of BuiltBy entries.
17 type MergeQuest struct { 17 type MergeQuest struct {
18 » Quest *model.Quest 18 » Quest *model.Quest
19 » AndThen []tumble.Mutation
19 } 20 }
20 21
21 // Root implements tumble.Mutation. 22 // Root implements tumble.Mutation.
22 func (m *MergeQuest) Root(c context.Context) *datastore.Key { 23 func (m *MergeQuest) Root(c context.Context) *datastore.Key {
23 » return datastore.Get(c).KeyForObj(m.Quest) 24 » return model.QuestKeyFromID(c, m.Quest.ID)
24 } 25 }
25 26
26 // RollForward implements tumble.Mutation. 27 // RollForward implements tumble.Mutation.
27 func (m *MergeQuest) RollForward(c context.Context) (muts []tumble.Mutation, err error) { 28 func (m *MergeQuest) RollForward(c context.Context) (muts []tumble.Mutation, err error) {
28 ds := datastore.Get(c) 29 ds := datastore.Get(c)
29 30
30 » curQuest := &model.Quest{ID: m.Quest.ID} 31 » curQuest := model.QuestFromID(m.Quest.ID)
31 32
32 c = logging.SetField(c, "qid", m.Quest.ID) 33 c = logging.SetField(c, "qid", m.Quest.ID)
33 34
34 reason := "getting quest" 35 reason := "getting quest"
35 switch err = ds.Get(curQuest); err { 36 switch err = ds.Get(curQuest); err {
36 case nil: 37 case nil:
37 prevLen := len(curQuest.BuiltBy) 38 prevLen := len(curQuest.BuiltBy)
38 curQuest.BuiltBy.Add(m.Quest.BuiltBy...) 39 curQuest.BuiltBy.Add(m.Quest.BuiltBy...)
39 if len(curQuest.BuiltBy) > prevLen { 40 if len(curQuest.BuiltBy) > prevLen {
40 reason = "putting merged quest" 41 reason = "putting merged quest"
41 err = ds.Put(curQuest) 42 err = ds.Put(curQuest)
42 } 43 }
43 case datastore.ErrNoSuchEntity: 44 case datastore.ErrNoSuchEntity:
44 reason = "putting quest" 45 reason = "putting quest"
45 err = ds.Put(m.Quest) 46 err = ds.Put(m.Quest)
46 } 47 }
47 48
48 if err != nil { 49 if err != nil {
49 logging.WithError(err).Errorf(c, "%s", reason) 50 logging.WithError(err).Errorf(c, "%s", reason)
50 } 51 }
51 52
53 muts = m.AndThen
54
52 return 55 return
53 } 56 }
54 57
55 func init() { 58 func init() {
56 tumble.Register((*MergeQuest)(nil)) 59 tumble.Register((*MergeQuest)(nil))
57 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698