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

Side by Side Diff: scheduler/appengine/apiservers/scheduler.go

Issue 2945843002: scheduler WIP: add GetAllJobs api. (Closed)
Patch Set: Created 3 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 apiservers 5 package apiservers
6 6
7 import ( 7 import (
8 "github.com/luci/luci-go/scheduler/api/scheduler/v1" 8 "github.com/luci/luci-go/scheduler/api/scheduler/v1"
9 "github.com/luci/luci-go/scheduler/appengine/catalog" 9 "github.com/luci/luci-go/scheduler/appengine/catalog"
10 "github.com/luci/luci-go/scheduler/appengine/engine" 10 "github.com/luci/luci-go/scheduler/appengine/engine"
11 ) 11 )
12 import (
13 context "golang.org/x/net/context"
Vadim Sh. 2017/06/19 17:44:19 move this import to existing imports section, befo
tandrii(chromium) 2017/06/20 11:48:05 Done. TBH, i learned to ignore import sections in
14 )
12 15
13 // SchedulerServer implements scheduler.Scheduler API. 16 // SchedulerServer implements scheduler.Scheduler API.
14 type SchedulerServer struct { 17 type SchedulerServer struct {
15 Engine engine.Engine 18 Engine engine.Engine
16 Catalog catalog.Catalog 19 Catalog catalog.Catalog
17 } 20 }
18 21
19 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) 22 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil)
23
24 // GetJobs fetches all jobs satisfying JobsRequest and visibility ACLs.
25 func (s SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) (*scheduler.JobsReply, error) {
26 var ejobs []*engine.Job
27 var err error
28 if in.GetProject() == "" {
29 ejobs, err = s.Engine.GetAllJobs(ctx)
30 } else {
31 ejobs, err = s.Engine.GetProjectJobs(ctx, in.GetProject())
32 }
33 if err != nil {
34 return nil, err
Vadim Sh. 2017/06/19 17:44:19 gRPC methods should always return grpc errors, e.g
tandrii(chromium) 2017/06/20 11:48:05 Done.
35 }
36
37 jobs := make([]*scheduler.JobWithState, len(ejobs))
38 for i, ej := range ejobs {
39 jobs[i] = &scheduler.JobWithState{
40 Id: ej.JobID,
41 Project: ej.ProjectID,
42 Schedule: ej.Schedule,
43 State: &scheduler.JobState{
44 Kind: string(ej.State.State),
45 },
46 }
47 }
48 return &scheduler.JobsReply{Jobs: jobs}, nil
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698