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

Side by Side Diff: appengine/cmd/dm/mutate/ensure_attempt.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file 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/api/dm/service/v1" 11 "github.com/luci/luci-go/common/api/dm/service/v1"
12 "github.com/luci/luci-go/common/logging" 12 "github.com/luci/luci-go/common/logging"
13 "golang.org/x/net/context" 13 "golang.org/x/net/context"
14 ) 14 )
15 15
16 // EnsureAttempt ensures that the given Attempt exists. If it doesn't, it's 16 // EnsureAttempt ensures that the given Attempt exists. If it doesn't, it's
17 // created in a NeedsExecution state. 17 // created in a NeedsExecution state.
18 type EnsureAttempt struct { 18 type EnsureAttempt struct {
19 ID *dm.Attempt_ID 19 ID *dm.Attempt_ID
20 } 20 }
21 21
22 // Root implements tumble.Mutation. 22 // Root implements tumble.Mutation.
23 func (e *EnsureAttempt) Root(c context.Context) *datastore.Key { 23 func (e *EnsureAttempt) Root(c context.Context) *datastore.Key {
24 » return datastore.Get(c).KeyForObj(&model.Attempt{ID: *e.ID}) 24 » return model.AttemptKeyFromID(c, e.ID)
25 } 25 }
26 26
27 // RollForward implements tumble.Mutation. 27 // RollForward implements tumble.Mutation.
28 func (e *EnsureAttempt) RollForward(c context.Context) (muts []tumble.Mutation, err error) { 28 func (e *EnsureAttempt) RollForward(c context.Context) (muts []tumble.Mutation, err error) {
29 ds := datastore.Get(c) 29 ds := datastore.Get(c)
30 30
31 a := model.MakeAttempt(c, e.ID) 31 a := model.MakeAttempt(c, e.ID)
32 » err = ds.Get(a) 32 » if err = ds.Get(a); err != datastore.ErrNoSuchEntity {
33 » if err != datastore.ErrNoSuchEntity {
34 return 33 return
35 } 34 }
36 35
37 if err = ds.Put(a); err != nil { 36 if err = ds.Put(a); err != nil {
38 logging.WithError(err).Errorf(logging.SetField(c, "id", e.ID), " in put") 37 logging.WithError(err).Errorf(logging.SetField(c, "id", e.ID), " in put")
39 } 38 }
39 muts = append(muts, &ScheduleExecution{e.ID})
40 return 40 return
41 } 41 }
42 42
43 func init() { 43 func init() {
44 tumble.Register((*EnsureAttempt)(nil)) 44 tumble.Register((*EnsureAttempt)(nil))
45 } 45 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/mutate/add_finished_deps_test.go ('k') | appengine/cmd/dm/mutate/ensure_attempt_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698