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/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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 Name: ej.GetJobName(), | 45 Name: ej.GetJobName(), |
46 Project: ej.ProjectID, | 46 Project: ej.ProjectID, |
47 Schedule: ej.Schedule, | 47 Schedule: ej.Schedule, |
48 State: &scheduler.JobState{ | 48 State: &scheduler.JobState{ |
49 UiStatus: string(presentation.GetPublicStateKind
(ej, traits)), | 49 UiStatus: string(presentation.GetPublicStateKind
(ej, traits)), |
50 }, | 50 }, |
51 } | 51 } |
52 } | 52 } |
53 return &scheduler.JobsReply{Jobs: jobs}, nil | 53 return &scheduler.JobsReply{Jobs: jobs}, nil |
54 } | 54 } |
| 55 |
| 56 func (s SchedulerServer) GetInvocations(ctx context.Context, in *scheduler.Invoc
ationsRequest) (*scheduler.InvocationsReply, error) { |
| 57 ejob, err := s.Engine.GetJob(ctx, in.GetProject()+"/"+in.GetJob()) |
| 58 if err != nil { |
| 59 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e
rr) |
| 60 } |
| 61 if ejob == nil { |
| 62 return nil, grpc.Errorf(codes.NotFound, "Job does not exist or y
ou have no access") |
| 63 } |
| 64 |
| 65 pageSize := 50 |
| 66 if in.PageSize > 0 && int(in.PageSize) < pageSize { |
| 67 pageSize = int(in.PageSize) |
| 68 } |
| 69 |
| 70 einvs, cursor, err := s.Engine.ListInvocations(ctx, ejob.JobID, pageSize
, in.GetCursor()) |
| 71 if err != nil { |
| 72 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e
rr) |
| 73 } |
| 74 invs := make([]*scheduler.Invocation, len(einvs)) |
| 75 for i, einv := range einvs { |
| 76 invs[i] = &scheduler.Invocation{ |
| 77 Id: einv.ID, |
| 78 Job: ejob.GetJobName(), |
| 79 Project: ejob.ProjectID, |
| 80 StartedTs: einv.Started.UnixNano() / 1000, |
| 81 TriggeredBy: string(einv.TriggeredBy), |
| 82 Status: string(einv.Status), |
| 83 Final: einv.Status.Final(), |
| 84 ConfigRevision: einv.Revision, |
| 85 ViewUrl: einv.ViewURL, |
| 86 } |
| 87 if einv.Status.Final() { |
| 88 invs[i].FinishedTs = einv.Finished.UnixNano() / 1000 |
| 89 } |
| 90 } |
| 91 return &scheduler.InvocationsReply{Invocations: invs, NextCursor: cursor
}, nil |
| 92 } |
OLD | NEW |