OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package model | 5 package model |
6 | 6 |
7 import ( | 7 import ( |
8 "crypto/subtle" | 8 "crypto/subtle" |
9 "fmt" | 9 "fmt" |
10 | 10 |
11 "github.com/luci/gae/service/datastore" | 11 "github.com/luci/gae/service/datastore" |
12 "github.com/luci/luci-go/appengine/cmd/dm/enums/attempt" | 12 "github.com/luci/luci-go/appengine/cmd/dm/enums/attempt" |
| 13 "github.com/luci/luci-go/appengine/cmd/dm/enums/execution" |
13 "github.com/luci/luci-go/appengine/cmd/dm/types" | 14 "github.com/luci/luci-go/appengine/cmd/dm/types" |
14 "github.com/luci/luci-go/common/logging" | 15 "github.com/luci/luci-go/common/logging" |
15 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
16 ) | 17 ) |
17 | 18 |
18 // Execution represents either an ongoing execution on the Quest's specified | 19 // Execution represents either an ongoing execution on the Quest's specified |
19 // distributor, or is a placeholder for an already-completed Execution. | 20 // distributor, or is a placeholder for an already-completed Execution. |
20 type Execution struct { | 21 type Execution struct { |
21 ID types.UInt32 `gae:"$id"` | 22 ID types.UInt32 `gae:"$id"` |
22 Attempt *datastore.Key `gae:"$parent"` | 23 Attempt *datastore.Key `gae:"$parent"` |
23 | 24 |
24 // ExecutionKey is a randomized nonce that's used to identify API calls
from | 25 // ExecutionKey is a randomized nonce that's used to identify API calls
from |
25 // the current execution to dungeon master. Once DM decides that the exe
cution | 26 // the current execution to dungeon master. Once DM decides that the exe
cution |
26 // should no longer be able to make API calls (e.g. it uploaded a result
or | 27 // should no longer be able to make API calls (e.g. it uploaded a result
or |
27 // added new dependencies), DM will revoke this key, making all further
API | 28 // added new dependencies), DM will revoke this key, making all further
API |
28 // access invalid. | 29 // access invalid. |
29 ExecutionKey []byte `gae:",noindex"` | 30 ExecutionKey []byte `gae:",noindex"` |
| 31 |
| 32 Status execution.State |
| 33 StatusReason string `gae:",noindex"` |
30 } | 34 } |
31 | 35 |
32 // Done returns true iff the Execution is done (i.e. it has a blank | 36 // Done returns true iff the Execution is done (i.e. it has a blank |
33 // ExecutionKey). | 37 // ExecutionKey). |
34 func (e *Execution) Done() bool { | 38 func (e *Execution) Done() bool { |
35 return len(e.ExecutionKey) == 0 | 39 return len(e.ExecutionKey) == 0 |
36 } | 40 } |
37 | 41 |
38 // Revoke will null-out the ExecutionKey and Put this Execution to the | 42 // Revoke will null-out the ExecutionKey and Put this Execution to the |
39 // datastore. | 43 // datastore. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // revokes the execution key. | 90 // revokes the execution key. |
87 // | 91 // |
88 // As a bonus, it will return the loaded Attempt and Execution. | 92 // As a bonus, it will return the loaded Attempt and Execution. |
89 func InvalidateExecution(c context.Context, aid *types.AttemptID, evkey []byte)
(*Attempt, *Execution, error) { | 93 func InvalidateExecution(c context.Context, aid *types.AttemptID, evkey []byte)
(*Attempt, *Execution, error) { |
90 a, e, err := verifyExecutionInternal(c, aid, evkey) | 94 a, e, err := verifyExecutionInternal(c, aid, evkey) |
91 if err != nil { | 95 if err != nil { |
92 return nil, nil, err | 96 return nil, nil, err |
93 } | 97 } |
94 return a, e, e.Revoke(c) | 98 return a, e, e.Revoke(c) |
95 } | 99 } |
OLD | NEW |