1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package personalize
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/personalize/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Gets a list of the batch inference jobs that have been performed off of a
16// solution version.
17func (c *Client) ListBatchInferenceJobs(ctx context.Context, params *ListBatchInferenceJobsInput, optFns ...func(*Options)) (*ListBatchInferenceJobsOutput, error) {
18	if params == nil {
19		params = &ListBatchInferenceJobsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListBatchInferenceJobs", params, optFns, addOperationListBatchInferenceJobsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListBatchInferenceJobsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListBatchInferenceJobsInput struct {
33
34	// The maximum number of batch inference job results to return in each page. The
35	// default value is 100.
36	MaxResults *int32
37
38	// The token to request the next page of results.
39	NextToken *string
40
41	// The Amazon Resource Name (ARN) of the solution version from which the batch
42	// inference jobs were created.
43	SolutionVersionArn *string
44}
45
46type ListBatchInferenceJobsOutput struct {
47
48	// A list containing information on each job that is returned.
49	BatchInferenceJobs []types.BatchInferenceJobSummary
50
51	// The token to use to retreive the next page of results. The value is null when
52	// there are no more results to return.
53	NextToken *string
54
55	// Metadata pertaining to the operation's result.
56	ResultMetadata middleware.Metadata
57}
58
59func addOperationListBatchInferenceJobsMiddlewares(stack *middleware.Stack, options Options) (err error) {
60	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListBatchInferenceJobs{}, middleware.After)
61	if err != nil {
62		return err
63	}
64	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListBatchInferenceJobs{}, middleware.After)
65	if err != nil {
66		return err
67	}
68	if err = addSetLoggerMiddleware(stack, options); err != nil {
69		return err
70	}
71	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
72		return err
73	}
74	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
75		return err
76	}
77	if err = addResolveEndpointMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
81		return err
82	}
83	if err = addRetryMiddlewares(stack, options); err != nil {
84		return err
85	}
86	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
87		return err
88	}
89	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
93		return err
94	}
95	if err = addClientUserAgent(stack); err != nil {
96		return err
97	}
98	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListBatchInferenceJobs(options.Region), middleware.Before); err != nil {
105		return err
106	}
107	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
108		return err
109	}
110	if err = addResponseErrorMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addRequestResponseLogging(stack, options); err != nil {
114		return err
115	}
116	return nil
117}
118
119// ListBatchInferenceJobsAPIClient is a client that implements the
120// ListBatchInferenceJobs operation.
121type ListBatchInferenceJobsAPIClient interface {
122	ListBatchInferenceJobs(context.Context, *ListBatchInferenceJobsInput, ...func(*Options)) (*ListBatchInferenceJobsOutput, error)
123}
124
125var _ ListBatchInferenceJobsAPIClient = (*Client)(nil)
126
127// ListBatchInferenceJobsPaginatorOptions is the paginator options for
128// ListBatchInferenceJobs
129type ListBatchInferenceJobsPaginatorOptions struct {
130	// The maximum number of batch inference job results to return in each page. The
131	// default value is 100.
132	Limit int32
133
134	// Set to true if pagination should stop if the service returns a pagination token
135	// that matches the most recent token provided to the service.
136	StopOnDuplicateToken bool
137}
138
139// ListBatchInferenceJobsPaginator is a paginator for ListBatchInferenceJobs
140type ListBatchInferenceJobsPaginator struct {
141	options   ListBatchInferenceJobsPaginatorOptions
142	client    ListBatchInferenceJobsAPIClient
143	params    *ListBatchInferenceJobsInput
144	nextToken *string
145	firstPage bool
146}
147
148// NewListBatchInferenceJobsPaginator returns a new ListBatchInferenceJobsPaginator
149func NewListBatchInferenceJobsPaginator(client ListBatchInferenceJobsAPIClient, params *ListBatchInferenceJobsInput, optFns ...func(*ListBatchInferenceJobsPaginatorOptions)) *ListBatchInferenceJobsPaginator {
150	options := ListBatchInferenceJobsPaginatorOptions{}
151	if params.MaxResults != nil {
152		options.Limit = *params.MaxResults
153	}
154
155	for _, fn := range optFns {
156		fn(&options)
157	}
158
159	if params == nil {
160		params = &ListBatchInferenceJobsInput{}
161	}
162
163	return &ListBatchInferenceJobsPaginator{
164		options:   options,
165		client:    client,
166		params:    params,
167		firstPage: true,
168	}
169}
170
171// HasMorePages returns a boolean indicating whether more pages are available
172func (p *ListBatchInferenceJobsPaginator) HasMorePages() bool {
173	return p.firstPage || p.nextToken != nil
174}
175
176// NextPage retrieves the next ListBatchInferenceJobs page.
177func (p *ListBatchInferenceJobsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListBatchInferenceJobsOutput, error) {
178	if !p.HasMorePages() {
179		return nil, fmt.Errorf("no more pages available")
180	}
181
182	params := *p.params
183	params.NextToken = p.nextToken
184
185	var limit *int32
186	if p.options.Limit > 0 {
187		limit = &p.options.Limit
188	}
189	params.MaxResults = limit
190
191	result, err := p.client.ListBatchInferenceJobs(ctx, &params, optFns...)
192	if err != nil {
193		return nil, err
194	}
195	p.firstPage = false
196
197	prevToken := p.nextToken
198	p.nextToken = result.NextToken
199
200	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
201		p.nextToken = nil
202	}
203
204	return result, nil
205}
206
207func newServiceMetadataMiddleware_opListBatchInferenceJobs(region string) *awsmiddleware.RegisterServiceMetadata {
208	return &awsmiddleware.RegisterServiceMetadata{
209		Region:        region,
210		ServiceID:     ServiceID,
211		SigningName:   "personalize",
212		OperationName: "ListBatchInferenceJobs",
213	}
214}
215