Skip to content

Commit

Permalink
GetRun paginates tasks and iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
gkiko10 committed Nov 8, 2024
1 parent dfdebe3 commit d5bbaa0
Show file tree
Hide file tree
Showing 2 changed files with 403 additions and 0 deletions.
33 changes: 33 additions & 0 deletions service/jobs/ext_api.go
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
package jobs

import "context"

// GetRun retrieves a run based on the provided request.
// It handles pagination if the run contains multiple iterations or tasks.
func (a *JobsAPI) GetRun(ctx context.Context, request GetRunRequest) (*Run, error) {
run, err := a.jobsImpl.GetRun(ctx, request)
if err != nil {
return nil, err
}

// 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.
// 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.
isPaginatingIterations := run.Iterations != nil && len(run.Iterations) > 0

pageToken := run.NextPageToken
for pageToken != "" {
request.PageToken = pageToken
nextRun, err := a.jobsImpl.GetRun(ctx, request)
if err != nil {
return nil, err
}

if isPaginatingIterations {
run.Iterations = append(run.Iterations, nextRun.Iterations...)
} else {
run.Tasks = append(run.Tasks, nextRun.Tasks...)
}
pageToken = nextRun.NextPageToken
}

return run, nil
}
Loading

0 comments on commit d5bbaa0

Please sign in to comment.