OLD | NEW |
---|---|
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/common/clock" | |
8 "github.com/luci/luci-go/scheduler/api/scheduler/v1" | 9 "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
9 "github.com/luci/luci-go/scheduler/appengine/catalog" | 10 "github.com/luci/luci-go/scheduler/appengine/catalog" |
10 "github.com/luci/luci-go/scheduler/appengine/engine" | 11 "github.com/luci/luci-go/scheduler/appengine/engine" |
11 "github.com/luci/luci-go/scheduler/appengine/presentation" | 12 "github.com/luci/luci-go/scheduler/appengine/presentation" |
12 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
13 "google.golang.org/grpc" | 14 "google.golang.org/grpc" |
14 "google.golang.org/grpc/codes" | 15 "google.golang.org/grpc/codes" |
16 "google.golang.org/grpc/status" | |
15 ) | 17 ) |
16 | 18 |
17 // SchedulerServer implements scheduler.Scheduler API. | 19 // SchedulerServer implements scheduler.Scheduler API. |
18 type SchedulerServer struct { | 20 type SchedulerServer struct { |
19 Engine engine.Engine | 21 Engine engine.Engine |
20 Catalog catalog.Catalog | 22 Catalog catalog.Catalog |
21 } | 23 } |
22 | 24 |
23 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) | 25 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) |
24 | 26 |
(...skipping 20 matching lines...) Expand all Loading... | |
45 Name: ej.GetJobName(), | 47 Name: ej.GetJobName(), |
46 Project: ej.ProjectID, | 48 Project: ej.ProjectID, |
47 Schedule: ej.Schedule, | 49 Schedule: ej.Schedule, |
48 State: &scheduler.JobState{ | 50 State: &scheduler.JobState{ |
49 UiStatus: string(presentation.GetPublicStateKind (ej, traits)), | 51 UiStatus: string(presentation.GetPublicStateKind (ej, traits)), |
50 }, | 52 }, |
51 } | 53 } |
52 } | 54 } |
53 return &scheduler.JobsReply{Jobs: jobs}, nil | 55 return &scheduler.JobsReply{Jobs: jobs}, nil |
54 } | 56 } |
57 | |
58 func (s SchedulerServer) GetInvocations(ctx context.Context, in *scheduler.Invoc ationsRequest) (*scheduler.InvocationsReply, error) { | |
59 ejob, err := s.Engine.GetJob(ctx, in.GetProject()+"/"+in.GetJob()) | |
60 if err != nil { | |
61 return nil, status.Errorf(codes.Internal, "datastore error: %s", err) | |
Vadim Sh.
2017/06/21 23:46:41
we don't support 'status'
use grpc.Errorf(...)
tandrii(chromium)
2017/06/22 15:47:42
https://godoc.org/google.golang.org/grpc#Errorf sa
Vadim Sh.
2017/06/22 17:06:25
well.. I now for sure that pRPC implementation ign
tandrii(chromium)
2017/06/22 17:44:17
OK, changed back. Now I wonder: is returning codes
| |
62 } | |
63 if ejob == nil { | |
64 return nil, status.Error(codes.NotFound, "Job does not exist or you have no access") | |
65 } | |
66 | |
67 pageSize := 50 | |
Vadim Sh.
2017/06/21 23:46:41
note in proto that 50 is default and maximum
tandrii(chromium)
2017/06/22 15:47:42
Done. I don't have a good way to choose the maximu
| |
68 if in.PageSize > 0 && int(in.PageSize) < pageSize { | |
69 pageSize = int(in.PageSize) | |
70 } | |
71 | |
72 nowTs := clock.Now(ctx).UnixNano() / 1000 | |
73 einvs, cursor, err := s.Engine.ListInvocations(ctx, ejob.JobID, pageSize , in.GetCursor()) | |
74 if err != nil { | |
75 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e rr) | |
76 } | |
77 invs := make([]*scheduler.Invocation, len(einvs)) | |
78 for i, einv := range einvs { | |
79 invs[i] = &scheduler.Invocation{ | |
80 Id: einv.ID, | |
81 Job: ejob.GetJobName(), | |
82 Project: ejob.ProjectID, | |
83 StartedTs: einv.Started.UnixNano() / 1000, | |
84 TriggeredBy: string(einv.TriggeredBy), | |
85 Status: string(einv.Status), | |
86 Final: einv.Status.Final(), | |
87 ConfigRevision: einv.Revision, | |
88 ViewUrl: einv.ViewURL, | |
89 } | |
90 if einv.Status.Final() { | |
91 invs[i].FinishedTs = einv.Finished.UnixNano() / 1000 | |
92 } | |
93 } | |
94 return &scheduler.InvocationsReply{ | |
95 Invocations: invs, | |
96 NextCursor: cursor, | |
97 NowTs: nowTs, | |
98 }, nil | |
99 } | |
OLD | NEW |