Skip to content

Commit 1981951

Browse files
authored
[Internal] Update Jobs GetRun API to support paginated responses for jobs and ForEach tasks (#1089)
## What changes are proposed in this pull request? Introduces extension for jobs GetRun call that paginates tasks and iterations arrays in the response. This change is necessary to prepare for jobs API 2.2 release that serves paginated response. Pagination is over once the `next_page_token` is absent from the response. The pagination logic is not exposed to the customer. ## How is this tested? Unit test and manual test. I wrote go code that called the new logic and verified that the returned result contained full object when the API was paginated.
1 parent 776b63c commit 1981951

File tree

2 files changed

+405
-0
lines changed

2 files changed

+405
-0
lines changed

service/jobs/ext_api.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package jobs
2+
3+
import "context"
4+
5+
// GetRun retrieves a run based on the provided request.
6+
// It handles pagination if the run contains multiple iterations or tasks.
7+
func (a *JobsAPI) GetRun(ctx context.Context, request GetRunRequest) (*Run, error) {
8+
run, err := a.jobsImpl.GetRun(ctx, request)
9+
if err != nil {
10+
return nil, err
11+
}
12+
13+
// When querying a Job run, a page token is returned when there are more than 100 tasks. No iterations are defined for a Job run. Therefore, the next page in the response only includes the next page of tasks.
14+
// When querying a ForEach task run, a page token is returned when there are more than 100 iterations. Only a single task is returned, corresponding to the ForEach task itself. Therefore, the client only reads the iterations from the next page and not the tasks.
15+
isPaginatingIterations := run.Iterations != nil && len(run.Iterations) > 0
16+
17+
pageToken := run.NextPageToken
18+
for pageToken != "" {
19+
request.PageToken = pageToken
20+
nextRun, err := a.jobsImpl.GetRun(ctx, request)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
if isPaginatingIterations {
26+
run.Iterations = append(run.Iterations, nextRun.Iterations...)
27+
} else {
28+
run.Tasks = append(run.Tasks, nextRun.Tasks...)
29+
}
30+
pageToken = nextRun.NextPageToken
31+
}
32+
33+
return run, nil
34+
}

0 commit comments

Comments
 (0)