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

Side by Side Diff: common/api/dm/service/v1/attempt_data.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: self review 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 "time" 8 "time"
9 9
10 google_pb "github.com/luci/luci-go/common/proto/google" 10 google_pb "github.com/luci/luci-go/common/proto/google"
11 ) 11 )
12 12
13 // NewAttemptNeedsExecution creates an Attempt in the NeedsExecution state. 13 // NewAttemptScheduling creates an Attempt in the SCHEDULING state.
14 func NewAttemptNeedsExecution(pending time.Time) *Attempt { 14 func NewAttemptScheduling() *Attempt {
15 return &Attempt{ 15 return &Attempt{
16 Data: &Attempt_Data{ 16 Data: &Attempt_Data{
17 » » » AttemptType: &Attempt_Data_NeedsExecution_{ 17 » » » AttemptType: &Attempt_Data_Scheduling_{
18 » » » » NeedsExecution: &Attempt_Data_NeedsExecution{ 18 » » » » &Attempt_Data_Scheduling{}}}}
19 » » » » » google_pb.NewTimestamp(pending)}}}}
20 } 19 }
21 20
22 // NewAttemptExecuting creates an Attempt in the Executing state. 21 // NewAttemptExecuting creates an Attempt in the EXECUTING state.
23 func NewAttemptExecuting(curExID uint32) *Attempt { 22 func NewAttemptExecuting(curExID uint32) *Attempt {
24 return &Attempt{ 23 return &Attempt{
25 Data: &Attempt_Data{ 24 Data: &Attempt_Data{
25 NumExecutions: curExID,
26 AttemptType: &Attempt_Data_Executing_{ 26 AttemptType: &Attempt_Data_Executing_{
27 » » » » Executing: &Attempt_Data_Executing{ 27 » » » » &Attempt_Data_Executing{curExID}}}}
28 » » » » » curExID}}}}
29 } 28 }
30 29
31 // NewAttemptAddingDeps creates an Attempt in the AddingDeps state. 30 // NewAttemptWaiting creates an Attempt in the WAITING state.
32 func NewAttemptAddingDeps(numAdding, numWaiting uint32) *Attempt { 31 func NewAttemptWaiting(numWaiting uint32) *Attempt {
33 return &Attempt{ 32 return &Attempt{
34 Data: &Attempt_Data{ 33 Data: &Attempt_Data{
35 » » » AttemptType: &Attempt_Data_AddingDeps_{ 34 » » » AttemptType: &Attempt_Data_Waiting_{
36 » » » » AddingDeps: &Attempt_Data_AddingDeps{ 35 » » » » &Attempt_Data_Waiting{numWaiting}}}}
37 » » » » » numAdding, numWaiting}}}}
38 } 36 }
39 37
40 // NewAttemptBlocked creates an Attempt in the Blocked state. 38 // NewAttemptFinished creates an Attempt in the FINISHED state.
41 func NewAttemptBlocked(numWaiting uint32) *Attempt { 39 func NewAttemptFinished(expiration time.Time, jsonResultSize uint32, jsonResult, finalPersistentState string) *Attempt {
42 » return &Attempt{
43 » » Data: &Attempt_Data{
44 » » » AttemptType: &Attempt_Data_Blocked_{
45 » » » » Blocked: &Attempt_Data_Blocked{
46 » » » » » numWaiting}}}}
47 }
48
49 // NewAttemptFinished creates an Attempt in the Finished state.
50 func NewAttemptFinished(expiration time.Time, jsonResultSize uint32, jsonResult string) *Attempt {
51 return &Attempt{ 40 return &Attempt{
52 Data: &Attempt_Data{ 41 Data: &Attempt_Data{
53 AttemptType: &Attempt_Data_Finished_{ 42 AttemptType: &Attempt_Data_Finished_{
54 » » » » Finished: &Attempt_Data_Finished{ 43 » » » » &Attempt_Data_Finished{
55 » » » » » google_pb.NewTimestamp(expiration), json ResultSize, jsonResult}}}} 44 » » » » » google_pb.NewTimestamp(expiration), json ResultSize, jsonResult, finalPersistentState}}}}
45 }
46
47 // NewAttemptAbnormalFinish creates an Attempt in the ABNORMAL_FINISH state.
48 func NewAttemptAbnormalFinish(af *AbnormalFinish) *Attempt {
49 » return &Attempt{
50 » » Data: &Attempt_Data{
51 » » » AttemptType: &Attempt_Data_AbnormalFinish{af}}}
56 } 52 }
57 53
58 // State computes the Attempt_State for the current Attempt_Data 54 // State computes the Attempt_State for the current Attempt_Data
59 func (d *Attempt_Data) State() Attempt_State { 55 func (d *Attempt_Data) State() Attempt_State {
60 » switch d.AttemptType.(type) { 56 » if d != nil {
61 » case *Attempt_Data_Executing_: 57 » » switch d.AttemptType.(type) {
62 » » return Attempt_EXECUTING 58 » » case *Attempt_Data_Scheduling_:
63 » case *Attempt_Data_AddingDeps_: 59 » » » return Attempt_SCHEDULING
64 » » return Attempt_ADDING_DEPS 60 » » case *Attempt_Data_Executing_:
65 » case *Attempt_Data_Blocked_: 61 » » » return Attempt_EXECUTING
66 » » return Attempt_BLOCKED 62 » » case *Attempt_Data_Waiting_:
67 » case *Attempt_Data_Finished_: 63 » » » return Attempt_WAITING
68 » » return Attempt_FINISHED 64 » » case *Attempt_Data_Finished_:
65 » » » return Attempt_FINISHED
66 » » case *Attempt_Data_AbnormalFinish:
67 » » » return Attempt_ABNORMAL_FINISHED
68 » » }
69 } 69 }
70 » // NEEDS_EXECUTION is the default 70 » return Attempt_SCHEDULING
71 » return Attempt_NEEDS_EXECUTION
72 } 71 }
73 72
74 // NormalizePartial will nil out the Partial field for this Attempt if all 73 // NormalizePartial will nil out the Partial field for this Attempt if all
75 // Partial fields are false. 74 // Partial fields are false.
76 func (d *Attempt) NormalizePartial() { 75 func (d *Attempt) NormalizePartial() {
77 p := d.GetPartial() 76 p := d.GetPartial()
78 if p == nil { 77 if p == nil {
79 return 78 return
80 } 79 }
81 if !(p.Data || p.Executions || p.FwdDeps || p.BackDeps || 80 if !(p.Data || p.Executions || p.FwdDeps || p.BackDeps ||
82 p.Result != Attempt_Partial_LOADED) { 81 p.Result != Attempt_Partial_LOADED) {
83 d.Partial = nil 82 d.Partial = nil
84 } 83 }
85 } 84 }
85
86 // Any returns true iff any of the Partial fields are true such that they could
87 // be successfully loaded on a subsequent query.
88 func (p *Attempt_Partial) Any() bool {
89 return (p.BackDeps || p.Data || p.Executions || p.FwdDeps ||
90 p.Result == Attempt_Partial_NOT_LOADED)
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698