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

Side by Side Diff: common/api/dm/service/v1/attempt_state_evolve.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 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 dm 5 package dm
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 ) 9 )
10 10
11 // validAttemptStateEvolution defines all valid {From -> []To} state 11 // validAttemptStateEvolution defines all valid {From -> []To} state
12 // transitions. The identity transition (X -> X) is implied, as long as X has an 12 // transitions. The identity transition (X -> X) is implied, as long as X has an
13 // entry in this mapping. 13 // entry in this mapping.
14 var validAttemptStateEvolution = map[Attempt_State][]Attempt_State{ 14 var validAttemptStateEvolution = map[Attempt_State][]Attempt_State{
15 » Attempt_ADDING_DEPS: {Attempt_BLOCKED, Attempt_NEEDS_EXECUT ION}, 15 » Attempt_SCHEDULING: {
16 » Attempt_BLOCKED: {Attempt_AWAITING_EXECUTION_STATE, Att empt_NEEDS_EXECUTION}, 16 » » Attempt_EXECUTING, // scheduled
17 » Attempt_AWAITING_EXECUTION_STATE: {Attempt_NEEDS_EXECUTION}, 17 » » Attempt_ABNORMAL_FINISHED, // cancelled/timeout/err/etc.
18 » Attempt_EXECUTING: {Attempt_ADDING_DEPS, Attempt_FINISHED }, 18 » },
19 » Attempt_FINISHED: {}, 19 » Attempt_EXECUTING: {
20 » Attempt_NEEDS_EXECUTION: {Attempt_EXECUTING}, 20 » » Attempt_SCHEDULING, // Retry
21 » » Attempt_WAITING, // EnsureGraphData
22 » » Attempt_FINISHED, // FinishAttempt
23 » » Attempt_ABNORMAL_FINISHED, // cancel/timeout/err/etc.
24 » },
25 » Attempt_WAITING: {
26 » » Attempt_SCHEDULING, // unblocked
27 » » Attempt_ABNORMAL_FINISHED, // cancelled
28 » },
29
30 » Attempt_FINISHED: {},
31 » Attempt_ABNORMAL_FINISHED: {},
21 } 32 }
22 33
23 // Evolve attempts to evolve the state of this Attempt. If the state evolution 34 // Evolve attempts to evolve the state of this Attempt. If the state evolution
24 // is not allowed (e.g. invalid state transition), this returns an error. 35 // is not allowed (e.g. invalid state transition), this returns an error.
25 func (s *Attempt_State) Evolve(newState Attempt_State) error { 36 func (s *Attempt_State) Evolve(newState Attempt_State) error {
26 nextStates := validAttemptStateEvolution[*s] 37 nextStates := validAttemptStateEvolution[*s]
27 if nextStates == nil { 38 if nextStates == nil {
28 return fmt.Errorf("invalid state transition: no transitions defi ned for %s", *s) 39 return fmt.Errorf("invalid state transition: no transitions defi ned for %s", *s)
29 } 40 }
30 41
(...skipping 17 matching lines...) Expand all
48 if err != nil { 59 if err != nil {
49 panic(err) 60 panic(err)
50 } 61 }
51 } 62 }
52 63
53 // Terminal returns true iff there are no valid evolutions from the current 64 // Terminal returns true iff there are no valid evolutions from the current
54 // state. 65 // state.
55 func (s Attempt_State) Terminal() bool { 66 func (s Attempt_State) Terminal() bool {
56 return len(validAttemptStateEvolution[s]) == 0 67 return len(validAttemptStateEvolution[s]) == 0
57 } 68 }
OLDNEW
« no previous file with comments | « common/api/dm/service/v1/attempt_data.go ('k') | common/api/dm/service/v1/attempt_state_evolve_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698