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

Side by Side Diff: appengine/cmd/dm/mutate/finish_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 "time" 8 "time"
9 9
10 "google.golang.org/grpc/codes" 10 "google.golang.org/grpc/codes"
(...skipping 12 matching lines...) Expand all
23 // Creates a new AttemptResult 23 // Creates a new AttemptResult
24 // Starts RecordCompletion state machine. 24 // Starts RecordCompletion state machine.
25 type FinishAttempt struct { 25 type FinishAttempt struct {
26 Auth *dm.Execution_Auth 26 Auth *dm.Execution_Auth
27 Result string 27 Result string
28 ResultExpiration time.Time 28 ResultExpiration time.Time
29 } 29 }
30 30
31 // Root implements tumble.Mutation 31 // Root implements tumble.Mutation
32 func (f *FinishAttempt) Root(c context.Context) *datastore.Key { 32 func (f *FinishAttempt) Root(c context.Context) *datastore.Key {
33 » return datastore.Get(c).KeyForObj(&model.Attempt{ID: *f.Auth.Id.AttemptI D()}) 33 » return model.AttemptKeyFromID(c, f.Auth.Id.AttemptID())
34 } 34 }
35 35
36 // RollForward implements tumble.Mutation 36 // RollForward implements tumble.Mutation
37 // 37 //
38 // This mutation is called directly from FinishAttempt, so we use 38 // This mutation is called directly from FinishAttempt, so we use
39 // grpcutil.MaybeLogErr 39 // grpcutil.MaybeLogErr
40 func (f *FinishAttempt) RollForward(c context.Context) (muts []tumble.Mutation, err error) { 40 func (f *FinishAttempt) RollForward(c context.Context) (muts []tumble.Mutation, err error) {
41 » atmpt, _, err := model.InvalidateExecution(c, f.Auth) 41 » atmpt, ex, err := model.InvalidateExecution(c, f.Auth)
42 if err != nil { 42 if err != nil {
43 return 43 return
44 } 44 }
45 45
46 if err = ResetExecutionTimeout(c, ex); err != nil {
47 return
48 }
49
46 ds := datastore.Get(c) 50 ds := datastore.Get(c)
47 51
48 // Executing -> Finished is valid, and we know we're already Executing b ecause
49 // the InvalidateExecution call above asserts that or errors out.
50 atmpt.MustModifyState(c, dm.Attempt_FINISHED)
51
52 atmpt.ResultSize = uint32(len(f.Result)) 52 atmpt.ResultSize = uint32(len(f.Result))
53 atmpt.ResultExpiration = f.ResultExpiration 53 atmpt.ResultExpiration = f.ResultExpiration
54 rslt := &model.AttemptResult{ 54 rslt := &model.AttemptResult{
55 Attempt: ds.KeyForObj(atmpt), 55 Attempt: ds.KeyForObj(atmpt),
56 Data: f.Result, 56 Data: f.Result,
57 Expiration: atmpt.ResultExpiration, 57 Expiration: atmpt.ResultExpiration,
58 Size: atmpt.ResultSize, 58 Size: atmpt.ResultSize,
59 } 59 }
60 60
61 err = grpcutil.MaybeLogErr(c, ds.Put(atmpt, rslt), 61 err = grpcutil.MaybeLogErr(c, ds.Put(atmpt, rslt),
62 » » codes.Internal, "while trying to PutMulti") 62 » » codes.Internal, "while trying to Put")
63
64 » // TODO(iannucci): also include mutations to generate index entries for
65 » // the attempt results.
66 » muts = append(muts, &RecordCompletion{For: f.Auth.Id.AttemptID()})
67 63
68 return 64 return
69 } 65 }
70 66
71 func init() { 67 func init() {
72 tumble.Register((*FinishAttempt)(nil)) 68 tumble.Register((*FinishAttempt)(nil))
73 } 69 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/mutate/ensure_quest_attempts_test.go ('k') | appengine/cmd/dm/mutate/finish_attempt_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698