Skip to content

Commit

Permalink
Enrich get job runs API (#297)
Browse files Browse the repository at this point in the history
* fix: enrich get job runs API response with job start and end times

* fix: update proton commit
  • Loading branch information
Mryashbhardwaj authored Nov 7, 2024
1 parent d937f02 commit 7e706d9
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 278 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NAME = "github.com/goto/optimus"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
OPMS_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "64b8a59fc433a186f5e8141624298875e7f95f4e"
PROTON_COMMIT := "526e657b03d243a4c9f880e6c4ffbe15b116afd5"


.PHONY: build test test-ci generate-proto unit-test-ci integration-test vet coverage clean install lint
Expand Down
14 changes: 9 additions & 5 deletions core/scheduler/handler/v1beta1/job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ func (h JobRunHandler) GetJobRuns(ctx context.Context, req *pb.GetJobRunsRequest
return nil, errors.GRPCErr(err, "unable to get job run for "+req.GetJobName())
}

var runs []*pb.JobRun
var runs []*pb.JobRunWithDetail
for _, run := range jobRuns {
ts := timestamppb.New(run.ScheduledAt)
runs = append(runs, &pb.JobRun{
jobRunWithDetail := pb.JobRunWithDetail{
State: run.State.String(),
ScheduledAt: ts,
})
ScheduledAt: timestamppb.New(run.ScheduledAt),
StartTime: timestamppb.New(run.StartTime),
}
if run.EndTime != nil {
jobRunWithDetail.EndTime = timestamppb.New(*run.EndTime)
}
runs = append(runs, &jobRunWithDetail)
}
return &pb.GetJobRunsResponse{JobRuns: runs}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions core/scheduler/service/job_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ func (s *JobRunService) GetJobRunsByFilter(ctx context.Context, projectName tena

jobRun, err := s.repo.GetLatestRun(ctx, projectName, jobName, runState)
if err != nil {
if errors.IsErrorType(err, errors.ErrNotFound) {
return []*scheduler.JobRun{}, nil
}
return nil, err
}
return []*scheduler.JobRun{jobRun}, nil
Expand Down
3 changes: 1 addition & 2 deletions internal/store/postgres/scheduler/job_run_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ func (j *JobRunRepository) GetRunsByTimeRange(ctx context.Context, project tenan
&jr.Status, &jr.SLADefinition, &jr.SLAAlert, &jr.Monitoring, &jr.CreatedAt)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
errMsg := fmt.Sprintf("no record for job: %s, scheduled between : %s -> %s, %s", jobName, since, until, stateClause)
return nil, errors.NotFound(scheduler.EntityJobRun, errMsg)
return []*scheduler.JobRun{}, nil
}
return nil, errors.Wrap(scheduler.EntityJobRun, "error while getting run", err)
}
Expand Down
624 changes: 363 additions & 261 deletions protos/gotocompany/optimus/core/v1beta1/job_run.pb.go

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions protos/gotocompany/optimus/core/v1beta1/job_run.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
"NULL_VALUE"
],
"default": "NULL_VALUE",
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\nThe JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
},
"rpcStatus": {
"type": "object",
Expand Down Expand Up @@ -415,7 +415,7 @@
"jobRuns": {
"type": "array",
"items": {
"$ref": "#/definitions/v1beta1JobRun"
"$ref": "#/definitions/v1beta1JobRunWithDetail"
}
}
}
Expand Down Expand Up @@ -509,6 +509,26 @@
}
}
},
"v1beta1JobRunWithDetail": {
"type": "object",
"properties": {
"state": {
"type": "string"
},
"scheduledAt": {
"type": "string",
"format": "date-time"
},
"startTime": {
"type": "string",
"format": "date-time"
},
"endTime": {
"type": "string",
"format": "date-time"
}
}
},
"v1beta1RegisterJobEventResponse": {
"type": "object"
},
Expand Down
8 changes: 4 additions & 4 deletions protos/gotocompany/optimus/core/v1beta1/namespace.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protos/gotocompany/optimus/core/v1beta1/project.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@
"NULL_VALUE"
],
"default": "NULL_VALUE",
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\nThe JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
},
"rpcStatus": {
"type": "object",
Expand Down

0 comments on commit 7e706d9

Please sign in to comment.