-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GetRun paginates tasks and iterations
- Loading branch information
Showing
2 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.