| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |