Chromium Code Reviews| Index: scheduler/appengine/apiservers/scheduler.go |
| diff --git a/scheduler/appengine/apiservers/scheduler.go b/scheduler/appengine/apiservers/scheduler.go |
| index 6cece118514558ea222f8dc80b621eb35cd63771..cf2f5a8669feb099e9af2dea7e3ffc15208e860e 100644 |
| --- a/scheduler/appengine/apiservers/scheduler.go |
| +++ b/scheduler/appengine/apiservers/scheduler.go |
| @@ -5,6 +5,7 @@ |
| package apiservers |
| import ( |
| + "github.com/luci/luci-go/common/clock" |
| "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
| "github.com/luci/luci-go/scheduler/appengine/catalog" |
| "github.com/luci/luci-go/scheduler/appengine/engine" |
| @@ -12,6 +13,7 @@ import ( |
| "golang.org/x/net/context" |
| "google.golang.org/grpc" |
| "google.golang.org/grpc/codes" |
| + "google.golang.org/grpc/status" |
| ) |
| // SchedulerServer implements scheduler.Scheduler API. |
| @@ -52,3 +54,46 @@ func (s SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) |
| } |
| return &scheduler.JobsReply{Jobs: jobs}, nil |
| } |
| + |
| +func (s SchedulerServer) GetInvocations(ctx context.Context, in *scheduler.InvocationsRequest) (*scheduler.InvocationsReply, error) { |
| + ejob, err := s.Engine.GetJob(ctx, in.GetProject()+"/"+in.GetJob()) |
| + if err != nil { |
| + 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
|
| + } |
| + if ejob == nil { |
| + return nil, status.Error(codes.NotFound, "Job does not exist or you have no access") |
| + } |
| + |
| + 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
|
| + if in.PageSize > 0 && int(in.PageSize) < pageSize { |
| + pageSize = int(in.PageSize) |
| + } |
| + |
| + nowTs := clock.Now(ctx).UnixNano() / 1000 |
| + einvs, cursor, err := s.Engine.ListInvocations(ctx, ejob.JobID, pageSize, in.GetCursor()) |
| + if err != nil { |
| + return nil, grpc.Errorf(codes.Internal, "datastore error: %s", err) |
| + } |
| + invs := make([]*scheduler.Invocation, len(einvs)) |
| + for i, einv := range einvs { |
| + invs[i] = &scheduler.Invocation{ |
| + Id: einv.ID, |
| + Job: ejob.GetJobName(), |
| + Project: ejob.ProjectID, |
| + StartedTs: einv.Started.UnixNano() / 1000, |
| + TriggeredBy: string(einv.TriggeredBy), |
| + Status: string(einv.Status), |
| + Final: einv.Status.Final(), |
| + ConfigRevision: einv.Revision, |
| + ViewUrl: einv.ViewURL, |
| + } |
| + if einv.Status.Final() { |
| + invs[i].FinishedTs = einv.Finished.UnixNano() / 1000 |
| + } |
| + } |
| + return &scheduler.InvocationsReply{ |
| + Invocations: invs, |
| + NextCursor: cursor, |
| + NowTs: nowTs, |
| + }, nil |
| +} |