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

Side by Side Diff: dm/appengine/distributor/distributor.go

Issue 2347973003: Refactor distributor API so that methods always get the Quest_Desc too. (Closed)
Patch Set: Created 4 years, 3 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 distributor contains all the adaptors for the various supported 5 // Package distributor contains all the adaptors for the various supported
6 // distributor protocols. At a high level, it works like this: 6 // distributor protocols. At a high level, it works like this:
7 // * Quests specify a distributor configuration by name as part of their 7 // * Quests specify a distributor configuration by name as part of their
8 // identity. 8 // identity.
9 // * When an Execution for that Quest NeedsExecution, DM reads configuration 9 // * When an Execution for that Quest NeedsExecution, DM reads configuration
10 // (distributor.proto) from luci-config. This configuration is stored 10 // (distributor.proto) from luci-config. This configuration is stored
11 // as part of the Execution so that for the duration of a given Exectuion, 11 // as part of the Execution so that for the duration of a given Exectuion,
12 // DM always interacts with the same distributor in the same way (barring 12 // DM always interacts with the same distributor in the same way (barring
13 // code changes in DM's adapter logic itself). 13 // code changes in DM's adapter logic itself).
14 // * DM uses the selected distributor implementation to start a task and 14 // * DM uses the selected distributor implementation to start a task and
15 // record its Token. Additionally, the distributor MUST subscribe to publish 15 // record its Token. Additionally, the distributor SHOULD subscribe to
Vadim Sh. 2016/09/20 00:24:26 "should subscribe to publish on topic" I cannot p
iannucci 2016/09/20 00:51:28 Fixed
16 // on DM's pubsub topic for updates. When publishing updates, the 16 // publish on DM's pubsub topic for updates. When publishing updates, the
17 // distributor MUST include 2 attributes (execution_id, pubsub_key), which 17 // distributor MUST include the token returned from PrepareTopic.
18 // are provided as part of TaskDescription.
19 // * When DM gets a hit on pubsub, it will load the Execution, load its cached 18 // * When DM gets a hit on pubsub, it will load the Execution, load its cached
20 // distributor configuration, and then call HandleNotification for the 19 // distributor configuration, and then call HandleNotification for the
21 // adapter to parse the notification body and return the state of the task. 20 // adapter to parse the notification body and return the state of the task.
22 // 21 //
23 // Adding a new distributor requires: 22 // Adding a new distributor requires:
24 // * Add a new subdir of protos with the configuration proto for the new 23 // * Add a new subdir of protos with the configuration proto for the new
25 // distributor. Each distributor implementation must have its own unique 24 // distributor. Each distributor implementation must have its own unique
26 // Config message. 25 // Config message.
27 // * Add a matching subdir of this package for the implementation of the 26 // * Add a matching subdir of this package for the implementation of the
28 // distributor. 27 // distributor.
(...skipping 27 matching lines...) Expand all
56 55
57 // D is the interface for all distributor implementations. 56 // D is the interface for all distributor implementations.
58 // 57 //
59 // Retries 58 // Retries
60 // 59 //
61 // Unless otherwise noted, DM will retry methods here if they return an error 60 // Unless otherwise noted, DM will retry methods here if they return an error
62 // marked as Transient, up to some internal limit. If they return 61 // marked as Transient, up to some internal limit. If they return
63 // a non-Transient error (or nil) DM will make a best effort not to duplicate 62 // a non-Transient error (or nil) DM will make a best effort not to duplicate
64 // calls, but it can't guarantee that. 63 // calls, but it can't guarantee that.
65 type D interface { 64 type D interface {
66 » // Run prepares and runs a new Task from the given TaskDescription. 65 » // Run prepares and runs a new Task from the given parameters.
67 // 66 //
68 » // Scheduling the same TaskDescription multiple times SHOULD return the same 67 » // Scheduling the same execution ID multiple times SHOULD return the sam e
69 // Token. It's OK if this doesn't happen, but only one of the scheduled tasks 68 // Token. It's OK if this doesn't happen, but only one of the scheduled tasks
70 // will be able to invoke ActivateExecution; the other one(s) will 69 // will be able to invoke ActivateExecution; the other one(s) will
71 // early-abort and/or timeout. 70 // early-abort and/or timeout.
72 // 71 //
73 // If this returns a non-Transient error, the Execution will be marked a s 72 // If this returns a non-Transient error, the Execution will be marked a s
74 // Rejected with the returned error message as the 'Reason'. 73 // Rejected with the returned error message as the 'Reason'.
75 // 74 //
76 // The various time durations, if non-zero, will be used verbatim for DM to 75 // The various time durations, if non-zero, will be used verbatim for DM to
77 // timeout that phase of the task's execution. If the task's execution t imes 76 // timeout that phase of the task's execution. If the task's execution t imes
78 // out in the 'STOPPING' phase, DM will poll the distributor's GetStatus 77 // out in the 'STOPPING' phase, DM will poll the distributor's GetStatus
79 // method up to 3 times with a 30-second gap to attempt to retrieve the final 78 // method up to 3 times with a 30-second gap to attempt to retrieve the final
80 // information. After more than 3 times, DM will give up and mark the ta sk as 79 // information. After more than 3 times, DM will give up and mark the ta sk as
81 // expired. 80 // expired.
82 // 81 //
83 // If the distributor doesn't intend to use Pubsub for notifying DM abou t the 82 // If the distributor doesn't intend to use Pubsub for notifying DM abou t the
84 // final status of the job, set pollTimeout to the amount of time you wa nt DM 83 // final status of the job, set pollTimeout to the amount of time you wa nt DM
85 // to wait before polling GetStatus. e.g. if after calling FinishAttempt or 84 // to wait before polling GetStatus. e.g. if after calling FinishAttempt or
86 // EnsureGraphData your distributor needs 10 seconds before it can corre ctly 85 // EnsureGraphData your distributor needs 10 seconds before it can corre ctly
87 // respond to a GetStatus request, you should set pollTimeout to >= 10s. 86 // respond to a GetStatus request, you should set pollTimeout to >= 10s.
88 // Otherwise pollTimeout should be set fairly high (e.g. 12 hours) as a hedge 87 // Otherwise pollTimeout should be set fairly high (e.g. 12 hours) as a hedge
89 // against a broken pubsub notification pipeline. 88 // against a broken pubsub notification pipeline.
90 // 89 //
91 // If you have the choice between pubsub or not, prefer to use pubsub as it 90 // If you have the choice between pubsub or not, prefer to use pubsub as it
92 // allows DM to more proactively update the graph state (and unblock wai ting 91 // allows DM to more proactively update the graph state (and unblock wai ting
93 // Attempts, etc.) 92 // Attempts, etc.)
94 » Run(*TaskDescription) (tok Token, pollTimeout time.Duration, err error) 93 » Run(qst *dm.Quest_Desc, auth *dm.Execution_Auth, prevResult *dm.JsonResu lt) (tok Token, pollTimeout time.Duration, err error)
95 94
96 // Cancel attempts to cancel a running task. If a task is canceled more than 95 // Cancel attempts to cancel a running task. If a task is canceled more than
97 // once, this should return nil. 96 // once, this should return nil.
98 » Cancel(Token) error 97 » Cancel(*dm.Quest_Desc, Token) error
99 98
100 // GetStatus retrieves the current state of the task from the distributo r. 99 // GetStatus retrieves the current state of the task from the distributo r.
101 // 100 //
102 // If this returns a non-Transient error more than 30 seconds after the task 101 // If this returns a non-Transient error more than 30 seconds after the task
103 // was Run(), the execution will be marked Missing with the returned err or 102 // was Run(), the execution will be marked Missing with the returned err or
104 // message as the 'Reason'. If it returns a non-Transient error within 3 0 103 // message as the 'Reason'. If it returns a non-Transient error within 3 0
105 // seconds of being run, DM will automatically treat that as Transient. 104 // seconds of being run, DM will automatically treat that as Transient.
106 » GetStatus(Token) (*dm.Result, error) 105 » GetStatus(*dm.Quest_Desc, Token) (*dm.Result, error)
107 106
108 // InfoURL calculates a user-presentable information url for the task 107 // InfoURL calculates a user-presentable information url for the task
109 // identified by Token. This should be a local operation, so it is not t he 108 // identified by Token. This should be a local operation, so it is not t he
110 // implementation's responsibility to validate the token in this method (e.g. 109 // implementation's responsibility to validate the token in this method (e.g.
111 // it could point to a non-existent job, etc.) 110 // it could point to a non-existent job, etc.)
112 InfoURL(Token) string 111 InfoURL(Token) string
113 112
114 // HandleNotification is called whenever DM receives a PubSub message se nt to 113 // HandleNotification is called whenever DM receives a PubSub message se nt to
115 » // a topic created with TaskDescription.PrepareTopic. The Attrs map will omit 114 » // a topic created with Config.PrepareTopic. The Attrs map will omit
116 // the 'auth_token' field. 115 // the 'auth_token' field.
117 // 116 //
118 // Returning (nil, nil) will indicate that DM should ignore this notific ation. 117 // Returning (nil, nil) will indicate that DM should ignore this notific ation.
119 // 118 //
120 // DM will convert pubsub Messages to a delayed GetStatus if a pubsub me ssage 119 // DM will convert pubsub Messages to a delayed GetStatus if a pubsub me ssage
121 // is delivered which refers to an Attempt whose status is NeedsExecutio n, 120 // is delivered which refers to an Attempt whose status is NeedsExecutio n,
122 // which could happen in the event of a not-fully-settled transacion. 121 // which could happen in the event of a not-fully-settled transacion.
123 // 122 //
124 // DM will ignore any notifications for executions which it doesn't know 123 // DM will ignore any notifications for executions which it doesn't know
125 // about. 124 // about.
126 » HandleNotification(notification *Notification) (*dm.Result, error) 125 » HandleNotification(qst *dm.Quest_Desc, notification *Notification) (*dm. Result, error)
127 126
128 // HandleTaskQueueTask is called if the distributor used Config.EnqueueT ask. 127 // HandleTaskQueueTask is called if the distributor used Config.EnqueueT ask.
129 // 128 //
130 // It may return zero or more Notifications for DM about arbitrary Execu tions. 129 // It may return zero or more Notifications for DM about arbitrary Execu tions.
131 // These notifications will be handled 'later' by the HandleNotification 130 // These notifications will be handled 'later' by the HandleNotification
132 // implementation. 131 // implementation.
133 » HandleTaskQueueTask(r *http.Request) ([]*Notification, error) 132 » HandleTaskQueueTask(*http.Request) ([]*Notification, error)
134 133
135 // Validate should return a non-nil error if the given distributor param eters 134 // Validate should return a non-nil error if the given distributor param eters
136 // are not appropriate for this Distributor. Payload is guaranteed to be 135 // are not appropriate for this Distributor. Payload is guaranteed to be
137 // a valid JSON object. This should validate that the content of that JS ON 136 // a valid JSON object. This should validate that the content of that JS ON
138 // object is what the distributor expects. 137 // object is what the distributor expects.
139 Validate(parameters string) error 138 Validate(parameters string) error
140 } 139 }
141 140
142 // Factory is a function which produces new distributor instance with the 141 // Factory is a function which produces new distributor instance with the
143 // provided configuration proto. 142 // provided configuration proto.
144 // 143 //
145 // c is guaranteed to be non-transactional. 144 // c is guaranteed to be non-transactional.
146 type Factory func(c context.Context, dist *Config) (D, error) 145 type Factory func(c context.Context, dist *Config) (D, error)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698