1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package mediaconvert
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/mediaconvert/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Retrieve a JSON array of up to twenty of your most recently created jobs. This
16// array includes in-process, completed, and errored jobs. This will return the
17// jobs themselves, not just a list of the jobs. To retrieve the twenty next most
18// recent jobs, use the nextToken string returned with the array.
19func (c *Client) ListJobs(ctx context.Context, params *ListJobsInput, optFns ...func(*Options)) (*ListJobsOutput, error) {
20	if params == nil {
21		params = &ListJobsInput{}
22	}
23
24	result, metadata, err := c.invokeOperation(ctx, "ListJobs", params, optFns, addOperationListJobsMiddlewares)
25	if err != nil {
26		return nil, err
27	}
28
29	out := result.(*ListJobsOutput)
30	out.ResultMetadata = metadata
31	return out, nil
32}
33
34type ListJobsInput struct {
35
36	// Optional. Number of jobs, up to twenty, that will be returned at one time.
37	MaxResults int32
38
39	// Optional. Use this string, provided with the response to a previous request, to
40	// request the next batch of jobs.
41	NextToken *string
42
43	// Optional. When you request lists of resources, you can specify whether they are
44	// sorted in ASCENDING or DESCENDING order. Default varies by resource.
45	Order types.Order
46
47	// Optional. Provide a queue name to get back only jobs from that queue.
48	Queue *string
49
50	// Optional. A job's status can be SUBMITTED, PROGRESSING, COMPLETE, CANCELED, or
51	// ERROR.
52	Status types.JobStatus
53}
54
55type ListJobsOutput struct {
56
57	// List of jobs
58	Jobs []types.Job
59
60	// Use this string to request the next batch of jobs.
61	NextToken *string
62
63	// Metadata pertaining to the operation's result.
64	ResultMetadata middleware.Metadata
65}
66
67func addOperationListJobsMiddlewares(stack *middleware.Stack, options Options) (err error) {
68	err = stack.Serialize.Add(&awsRestjson1_serializeOpListJobs{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListJobs{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	if err = addSetLoggerMiddleware(stack, options); err != nil {
77		return err
78	}
79	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
80		return err
81	}
82	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
83		return err
84	}
85	if err = addResolveEndpointMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
89		return err
90	}
91	if err = addRetryMiddlewares(stack, options); err != nil {
92		return err
93	}
94	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
95		return err
96	}
97	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
101		return err
102	}
103	if err = addClientUserAgent(stack); err != nil {
104		return err
105	}
106	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
107		return err
108	}
109	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
110		return err
111	}
112	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListJobs(options.Region), middleware.Before); err != nil {
113		return err
114	}
115	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
116		return err
117	}
118	if err = addResponseErrorMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addRequestResponseLogging(stack, options); err != nil {
122		return err
123	}
124	return nil
125}
126
127// ListJobsAPIClient is a client that implements the ListJobs operation.
128type ListJobsAPIClient interface {
129	ListJobs(context.Context, *ListJobsInput, ...func(*Options)) (*ListJobsOutput, error)
130}
131
132var _ ListJobsAPIClient = (*Client)(nil)
133
134// ListJobsPaginatorOptions is the paginator options for ListJobs
135type ListJobsPaginatorOptions struct {
136	// Optional. Number of jobs, up to twenty, that will be returned at one time.
137	Limit int32
138
139	// Set to true if pagination should stop if the service returns a pagination token
140	// that matches the most recent token provided to the service.
141	StopOnDuplicateToken bool
142}
143
144// ListJobsPaginator is a paginator for ListJobs
145type ListJobsPaginator struct {
146	options   ListJobsPaginatorOptions
147	client    ListJobsAPIClient
148	params    *ListJobsInput
149	nextToken *string
150	firstPage bool
151}
152
153// NewListJobsPaginator returns a new ListJobsPaginator
154func NewListJobsPaginator(client ListJobsAPIClient, params *ListJobsInput, optFns ...func(*ListJobsPaginatorOptions)) *ListJobsPaginator {
155	options := ListJobsPaginatorOptions{}
156	if params.MaxResults != 0 {
157		options.Limit = params.MaxResults
158	}
159
160	for _, fn := range optFns {
161		fn(&options)
162	}
163
164	if params == nil {
165		params = &ListJobsInput{}
166	}
167
168	return &ListJobsPaginator{
169		options:   options,
170		client:    client,
171		params:    params,
172		firstPage: true,
173	}
174}
175
176// HasMorePages returns a boolean indicating whether more pages are available
177func (p *ListJobsPaginator) HasMorePages() bool {
178	return p.firstPage || p.nextToken != nil
179}
180
181// NextPage retrieves the next ListJobs page.
182func (p *ListJobsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListJobsOutput, error) {
183	if !p.HasMorePages() {
184		return nil, fmt.Errorf("no more pages available")
185	}
186
187	params := *p.params
188	params.NextToken = p.nextToken
189
190	params.MaxResults = p.options.Limit
191
192	result, err := p.client.ListJobs(ctx, &params, optFns...)
193	if err != nil {
194		return nil, err
195	}
196	p.firstPage = false
197
198	prevToken := p.nextToken
199	p.nextToken = result.NextToken
200
201	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
202		p.nextToken = nil
203	}
204
205	return result, nil
206}
207
208func newServiceMetadataMiddleware_opListJobs(region string) *awsmiddleware.RegisterServiceMetadata {
209	return &awsmiddleware.RegisterServiceMetadata{
210		Region:        region,
211		ServiceID:     ServiceID,
212		SigningName:   "mediaconvert",
213		OperationName: "ListJobs",
214	}
215}
216