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 frontend implements GAE web server for luci-scheduler service. | 5 // Package frontend implements GAE web server for luci-scheduler service. |
6 // | 6 // |
7 // Due to the way classic GAE imports work, this package can not have | 7 // Due to the way classic GAE imports work, this package can not have |
8 // subpackages (or at least subpackages referenced via absolute import path). | 8 // subpackages (or at least subpackages referenced via absolute import path). |
9 // We can't use relative imports because luci-go will then become unbuildable | 9 // We can't use relative imports because luci-go will then become unbuildable |
10 // by regular (non GAE) toolset. | 10 // by regular (non GAE) toolset. |
(...skipping 17 matching lines...) Expand all Loading... |
28 tq "github.com/luci/gae/service/taskqueue" | 28 tq "github.com/luci/gae/service/taskqueue" |
29 | 29 |
30 "github.com/luci/luci-go/grpc/discovery" | 30 "github.com/luci/luci-go/grpc/discovery" |
31 "github.com/luci/luci-go/grpc/grpcmon" | 31 "github.com/luci/luci-go/grpc/grpcmon" |
32 "github.com/luci/luci-go/grpc/prpc" | 32 "github.com/luci/luci-go/grpc/prpc" |
33 "github.com/luci/luci-go/server/router" | 33 "github.com/luci/luci-go/server/router" |
34 | 34 |
35 "github.com/luci/luci-go/appengine/gaemiddleware" | 35 "github.com/luci/luci-go/appengine/gaemiddleware" |
36 | 36 |
37 "github.com/luci/luci-go/common/data/rand/mathrand" | 37 "github.com/luci/luci-go/common/data/rand/mathrand" |
38 "github.com/luci/luci-go/common/errors" | |
39 "github.com/luci/luci-go/common/logging" | 38 "github.com/luci/luci-go/common/logging" |
| 39 "github.com/luci/luci-go/common/retry/transient" |
40 | 40 |
41 "github.com/luci/luci-go/scheduler/api/scheduler/v1" | 41 "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
42 | 42 |
43 "github.com/luci/luci-go/scheduler/appengine/apiservers" | 43 "github.com/luci/luci-go/scheduler/appengine/apiservers" |
44 "github.com/luci/luci-go/scheduler/appengine/catalog" | 44 "github.com/luci/luci-go/scheduler/appengine/catalog" |
45 "github.com/luci/luci-go/scheduler/appengine/engine" | 45 "github.com/luci/luci-go/scheduler/appengine/engine" |
46 "github.com/luci/luci-go/scheduler/appengine/task" | 46 "github.com/luci/luci-go/scheduler/appengine/task" |
47 "github.com/luci/luci-go/scheduler/appengine/task/buildbucket" | 47 "github.com/luci/luci-go/scheduler/appengine/task/buildbucket" |
48 "github.com/luci/luci-go/scheduler/appengine/task/gitiles" | 48 "github.com/luci/luci-go/scheduler/appengine/task/gitiles" |
49 "github.com/luci/luci-go/scheduler/appengine/task/noop" | 49 "github.com/luci/luci-go/scheduler/appengine/task/noop" |
(...skipping 28 matching lines...) Expand all Loading... |
78 body := fmt.Sprintf(msg, args...) | 78 body := fmt.Sprintf(msg, args...) |
79 logging.Errorf(c.Context, "HTTP %d: %s", code, body) | 79 logging.Errorf(c.Context, "HTTP %d: %s", code, body) |
80 http.Error(c.Writer, body, code) | 80 http.Error(c.Writer, body, code) |
81 } | 81 } |
82 | 82 |
83 // err sets status to 500 on transient errors or 202 on fatal ones. Returning | 83 // err sets status to 500 on transient errors or 202 on fatal ones. Returning |
84 // status code in range [200–299] is the only way to tell Task Queues to stop | 84 // status code in range [200–299] is the only way to tell Task Queues to stop |
85 // retrying the task. | 85 // retrying the task. |
86 func (c *requestContext) err(e error, msg string, args ...interface{}) { | 86 func (c *requestContext) err(e error, msg string, args ...interface{}) { |
87 code := 500 | 87 code := 500 |
88 » if !errors.IsTransient(e) { | 88 » if !transient.Tag.In(e) { |
89 code = 202 | 89 code = 202 |
90 } | 90 } |
91 args = append(args, e) | 91 args = append(args, e) |
92 c.fail(code, msg+" - %s", args...) | 92 c.fail(code, msg+" - %s", args...) |
93 } | 93 } |
94 | 94 |
95 // ok sets status to 200 and puts "OK" in response. | 95 // ok sets status to 200 and puts "OK" in response. |
96 func (c *requestContext) ok() { | 96 func (c *requestContext) ok() { |
97 c.Writer.Header().Set("Content-Type", "text/plain; charset=utf-8") | 97 c.Writer.Header().Set("Content-Type", "text/plain; charset=utf-8") |
98 c.Writer.WriteHeader(200) | 98 c.Writer.WriteHeader(200) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 // Handle each project in its own task to avoid "bad" projects (e.g. one
s with | 247 // Handle each project in its own task to avoid "bad" projects (e.g. one
s with |
248 // lots of jobs) to slow down "good" ones. | 248 // lots of jobs) to slow down "good" ones. |
249 tasks := make([]*tq.Task, 0, len(projectsToVisit)) | 249 tasks := make([]*tq.Task, 0, len(projectsToVisit)) |
250 for projectID := range projectsToVisit { | 250 for projectID := range projectsToVisit { |
251 tasks = append(tasks, &tq.Task{ | 251 tasks = append(tasks, &tq.Task{ |
252 Path: "/internal/tasks/read-project-config?projectID=" +
url.QueryEscape(projectID), | 252 Path: "/internal/tasks/read-project-config?projectID=" +
url.QueryEscape(projectID), |
253 }) | 253 }) |
254 } | 254 } |
255 if err = tq.Add(rc.Context, "read-project-config", tasks...); err != nil
{ | 255 if err = tq.Add(rc.Context, "read-project-config", tasks...); err != nil
{ |
256 » » rc.err(errors.WrapTransient(err), "Failed to add tasks to task q
ueue") | 256 » » rc.err(transient.Tag.Apply(err), "Failed to add tasks to task qu
eue") |
257 } else { | 257 } else { |
258 rc.ok() | 258 rc.ok() |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 // readProjectConfigTask grabs a list of jobs in a project from catalog, updates | 262 // readProjectConfigTask grabs a list of jobs in a project from catalog, updates |
263 // all changed jobs, adds new ones, disables old ones. | 263 // all changed jobs, adds new ones, disables old ones. |
264 func readProjectConfigTask(c *router.Context) { | 264 func readProjectConfigTask(c *router.Context) { |
265 rc := requestContext(*c) | 265 rc := requestContext(*c) |
266 projectID := rc.Request.URL.Query().Get("projectID") | 266 projectID := rc.Request.URL.Query().Get("projectID") |
(...skipping 25 matching lines...) Expand all Loading... |
292 return | 292 return |
293 } | 293 } |
294 count, _ := strconv.Atoi(rc.Request.Header.Get("X-AppEngine-TaskExecutio
nCount")) | 294 count, _ := strconv.Atoi(rc.Request.Header.Get("X-AppEngine-TaskExecutio
nCount")) |
295 err = globalEngine.ExecuteSerializedAction(rc.Context, body, count) | 295 err = globalEngine.ExecuteSerializedAction(rc.Context, body, count) |
296 if err != nil { | 296 if err != nil { |
297 rc.err(err, "Error when executing the action") | 297 rc.err(err, "Error when executing the action") |
298 return | 298 return |
299 } | 299 } |
300 rc.ok() | 300 rc.ok() |
301 } | 301 } |
OLD | NEW |