1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package batch 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/batch/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of AWS Batch jobs. You must specify only one of the following 16// items: 17// 18// * A job queue ID to return a list of jobs in that job queue 19// 20// * A 21// multi-node parallel job ID to return a list of nodes for that job 22// 23// * An array 24// job ID to return a list of the children for that job 25// 26// You can filter the results 27// by job status with the jobStatus parameter. If you don't specify a status, only 28// RUNNING jobs are returned. 29func (c *Client) ListJobs(ctx context.Context, params *ListJobsInput, optFns ...func(*Options)) (*ListJobsOutput, error) { 30 if params == nil { 31 params = &ListJobsInput{} 32 } 33 34 result, metadata, err := c.invokeOperation(ctx, "ListJobs", params, optFns, addOperationListJobsMiddlewares) 35 if err != nil { 36 return nil, err 37 } 38 39 out := result.(*ListJobsOutput) 40 out.ResultMetadata = metadata 41 return out, nil 42} 43 44// Contains the parameters for ListJobs. 45type ListJobsInput struct { 46 47 // The job ID for an array job. Specifying an array job ID with this parameter 48 // lists all child jobs from within the specified array. 49 ArrayJobId *string 50 51 // The name or full Amazon Resource Name (ARN) of the job queue used to list jobs. 52 JobQueue *string 53 54 // The job status used to filter jobs in the specified queue. If you don't specify 55 // a status, only RUNNING jobs are returned. 56 JobStatus types.JobStatus 57 58 // The maximum number of results returned by ListJobs in paginated output. When 59 // this parameter is used, ListJobs only returns maxResults results in a single 60 // page and a nextToken response element. The remaining results of the initial 61 // request can be seen by sending another ListJobs request with the returned 62 // nextToken value. This value can be between 1 and 100. If this parameter isn't 63 // used, then ListJobs returns up to 100 results and a nextToken value if 64 // applicable. 65 MaxResults int32 66 67 // The job ID for a multi-node parallel job. Specifying a multi-node parallel job 68 // ID with this parameter lists all nodes that are associated with the specified 69 // job. 70 MultiNodeJobId *string 71 72 // The nextToken value returned from a previous paginated ListJobs request where 73 // maxResults was used and the results exceeded the value of that parameter. 74 // Pagination continues from the end of the previous results that returned the 75 // nextToken value. This value is null when there are no more results to return. 76 // This token should be treated as an opaque identifier that's only used to 77 // retrieve the next items in a list and not for other programmatic purposes. 78 NextToken *string 79} 80 81type ListJobsOutput struct { 82 83 // A list of job summaries that match the request. 84 // 85 // This member is required. 86 JobSummaryList []types.JobSummary 87 88 // The nextToken value to include in a future ListJobs request. When the results of 89 // a ListJobs request exceed maxResults, this value can be used to retrieve the 90 // next page of results. This value is null when there are no more results to 91 // return. 92 NextToken *string 93 94 // Metadata pertaining to the operation's result. 95 ResultMetadata middleware.Metadata 96} 97 98func addOperationListJobsMiddlewares(stack *middleware.Stack, options Options) (err error) { 99 err = stack.Serialize.Add(&awsRestjson1_serializeOpListJobs{}, middleware.After) 100 if err != nil { 101 return err 102 } 103 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListJobs{}, middleware.After) 104 if err != nil { 105 return err 106 } 107 if err = addSetLoggerMiddleware(stack, options); err != nil { 108 return err 109 } 110 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 111 return err 112 } 113 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 114 return err 115 } 116 if err = addResolveEndpointMiddleware(stack, options); err != nil { 117 return err 118 } 119 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 120 return err 121 } 122 if err = addRetryMiddlewares(stack, options); err != nil { 123 return err 124 } 125 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 126 return err 127 } 128 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 129 return err 130 } 131 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 132 return err 133 } 134 if err = addClientUserAgent(stack); err != nil { 135 return err 136 } 137 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 138 return err 139 } 140 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 141 return err 142 } 143 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListJobs(options.Region), middleware.Before); err != nil { 144 return err 145 } 146 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 147 return err 148 } 149 if err = addResponseErrorMiddleware(stack); err != nil { 150 return err 151 } 152 if err = addRequestResponseLogging(stack, options); err != nil { 153 return err 154 } 155 return nil 156} 157 158// ListJobsAPIClient is a client that implements the ListJobs operation. 159type ListJobsAPIClient interface { 160 ListJobs(context.Context, *ListJobsInput, ...func(*Options)) (*ListJobsOutput, error) 161} 162 163var _ ListJobsAPIClient = (*Client)(nil) 164 165// ListJobsPaginatorOptions is the paginator options for ListJobs 166type ListJobsPaginatorOptions struct { 167 // The maximum number of results returned by ListJobs in paginated output. When 168 // this parameter is used, ListJobs only returns maxResults results in a single 169 // page and a nextToken response element. The remaining results of the initial 170 // request can be seen by sending another ListJobs request with the returned 171 // nextToken value. This value can be between 1 and 100. If this parameter isn't 172 // used, then ListJobs returns up to 100 results and a nextToken value if 173 // applicable. 174 Limit int32 175 176 // Set to true if pagination should stop if the service returns a pagination token 177 // that matches the most recent token provided to the service. 178 StopOnDuplicateToken bool 179} 180 181// ListJobsPaginator is a paginator for ListJobs 182type ListJobsPaginator struct { 183 options ListJobsPaginatorOptions 184 client ListJobsAPIClient 185 params *ListJobsInput 186 nextToken *string 187 firstPage bool 188} 189 190// NewListJobsPaginator returns a new ListJobsPaginator 191func NewListJobsPaginator(client ListJobsAPIClient, params *ListJobsInput, optFns ...func(*ListJobsPaginatorOptions)) *ListJobsPaginator { 192 if params == nil { 193 params = &ListJobsInput{} 194 } 195 196 options := ListJobsPaginatorOptions{} 197 if params.MaxResults != 0 { 198 options.Limit = params.MaxResults 199 } 200 201 for _, fn := range optFns { 202 fn(&options) 203 } 204 205 return &ListJobsPaginator{ 206 options: options, 207 client: client, 208 params: params, 209 firstPage: true, 210 } 211} 212 213// HasMorePages returns a boolean indicating whether more pages are available 214func (p *ListJobsPaginator) HasMorePages() bool { 215 return p.firstPage || p.nextToken != nil 216} 217 218// NextPage retrieves the next ListJobs page. 219func (p *ListJobsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListJobsOutput, error) { 220 if !p.HasMorePages() { 221 return nil, fmt.Errorf("no more pages available") 222 } 223 224 params := *p.params 225 params.NextToken = p.nextToken 226 227 params.MaxResults = p.options.Limit 228 229 result, err := p.client.ListJobs(ctx, ¶ms, optFns...) 230 if err != nil { 231 return nil, err 232 } 233 p.firstPage = false 234 235 prevToken := p.nextToken 236 p.nextToken = result.NextToken 237 238 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 239 p.nextToken = nil 240 } 241 242 return result, nil 243} 244 245func newServiceMetadataMiddleware_opListJobs(region string) *awsmiddleware.RegisterServiceMetadata { 246 return &awsmiddleware.RegisterServiceMetadata{ 247 Region: region, 248 ServiceID: ServiceID, 249 SigningName: "batch", 250 OperationName: "ListJobs", 251 } 252} 253