1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17package cloudtasks
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	gax "github.com/googleapis/gax-go/v2"
27	"google.golang.org/api/iterator"
28	"google.golang.org/api/option"
29	"google.golang.org/api/option/internaloption"
30	gtransport "google.golang.org/api/transport/grpc"
31	taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2"
32	iampb "google.golang.org/genproto/googleapis/iam/v1"
33	"google.golang.org/grpc"
34	"google.golang.org/grpc/codes"
35	"google.golang.org/grpc/metadata"
36	"google.golang.org/protobuf/proto"
37)
38
39var newClientHook clientHook
40
41// CallOptions contains the retry settings for each method of Client.
42type CallOptions struct {
43	ListQueues         []gax.CallOption
44	GetQueue           []gax.CallOption
45	CreateQueue        []gax.CallOption
46	UpdateQueue        []gax.CallOption
47	DeleteQueue        []gax.CallOption
48	PurgeQueue         []gax.CallOption
49	PauseQueue         []gax.CallOption
50	ResumeQueue        []gax.CallOption
51	GetIamPolicy       []gax.CallOption
52	SetIamPolicy       []gax.CallOption
53	TestIamPermissions []gax.CallOption
54	ListTasks          []gax.CallOption
55	GetTask            []gax.CallOption
56	CreateTask         []gax.CallOption
57	DeleteTask         []gax.CallOption
58	RunTask            []gax.CallOption
59}
60
61func defaultGRPCClientOptions() []option.ClientOption {
62	return []option.ClientOption{
63		internaloption.WithDefaultEndpoint("cloudtasks.googleapis.com:443"),
64		internaloption.WithDefaultMTLSEndpoint("cloudtasks.mtls.googleapis.com:443"),
65		internaloption.WithDefaultAudience("https://cloudtasks.googleapis.com/"),
66		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
67		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
68		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
69			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
70	}
71}
72
73func defaultCallOptions() *CallOptions {
74	return &CallOptions{
75		ListQueues: []gax.CallOption{
76			gax.WithRetry(func() gax.Retryer {
77				return gax.OnCodes([]codes.Code{
78					codes.DeadlineExceeded,
79					codes.Unavailable,
80				}, gax.Backoff{
81					Initial:    100 * time.Millisecond,
82					Max:        10000 * time.Millisecond,
83					Multiplier: 1.30,
84				})
85			}),
86		},
87		GetQueue: []gax.CallOption{
88			gax.WithRetry(func() gax.Retryer {
89				return gax.OnCodes([]codes.Code{
90					codes.DeadlineExceeded,
91					codes.Unavailable,
92				}, gax.Backoff{
93					Initial:    100 * time.Millisecond,
94					Max:        10000 * time.Millisecond,
95					Multiplier: 1.30,
96				})
97			}),
98		},
99		CreateQueue: []gax.CallOption{},
100		UpdateQueue: []gax.CallOption{},
101		DeleteQueue: []gax.CallOption{
102			gax.WithRetry(func() gax.Retryer {
103				return gax.OnCodes([]codes.Code{
104					codes.DeadlineExceeded,
105					codes.Unavailable,
106				}, gax.Backoff{
107					Initial:    100 * time.Millisecond,
108					Max:        10000 * time.Millisecond,
109					Multiplier: 1.30,
110				})
111			}),
112		},
113		PurgeQueue:  []gax.CallOption{},
114		PauseQueue:  []gax.CallOption{},
115		ResumeQueue: []gax.CallOption{},
116		GetIamPolicy: []gax.CallOption{
117			gax.WithRetry(func() gax.Retryer {
118				return gax.OnCodes([]codes.Code{
119					codes.DeadlineExceeded,
120					codes.Unavailable,
121				}, gax.Backoff{
122					Initial:    100 * time.Millisecond,
123					Max:        10000 * time.Millisecond,
124					Multiplier: 1.30,
125				})
126			}),
127		},
128		SetIamPolicy: []gax.CallOption{},
129		TestIamPermissions: []gax.CallOption{
130			gax.WithRetry(func() gax.Retryer {
131				return gax.OnCodes([]codes.Code{
132					codes.DeadlineExceeded,
133					codes.Unavailable,
134				}, gax.Backoff{
135					Initial:    100 * time.Millisecond,
136					Max:        10000 * time.Millisecond,
137					Multiplier: 1.30,
138				})
139			}),
140		},
141		ListTasks: []gax.CallOption{
142			gax.WithRetry(func() gax.Retryer {
143				return gax.OnCodes([]codes.Code{
144					codes.DeadlineExceeded,
145					codes.Unavailable,
146				}, gax.Backoff{
147					Initial:    100 * time.Millisecond,
148					Max:        10000 * time.Millisecond,
149					Multiplier: 1.30,
150				})
151			}),
152		},
153		GetTask: []gax.CallOption{
154			gax.WithRetry(func() gax.Retryer {
155				return gax.OnCodes([]codes.Code{
156					codes.DeadlineExceeded,
157					codes.Unavailable,
158				}, gax.Backoff{
159					Initial:    100 * time.Millisecond,
160					Max:        10000 * time.Millisecond,
161					Multiplier: 1.30,
162				})
163			}),
164		},
165		CreateTask: []gax.CallOption{},
166		DeleteTask: []gax.CallOption{
167			gax.WithRetry(func() gax.Retryer {
168				return gax.OnCodes([]codes.Code{
169					codes.DeadlineExceeded,
170					codes.Unavailable,
171				}, gax.Backoff{
172					Initial:    100 * time.Millisecond,
173					Max:        10000 * time.Millisecond,
174					Multiplier: 1.30,
175				})
176			}),
177		},
178		RunTask: []gax.CallOption{},
179	}
180}
181
182// internalClient is an interface that defines the methods availaible from Cloud Tasks API.
183type internalClient interface {
184	Close() error
185	setGoogleClientInfo(...string)
186	Connection() *grpc.ClientConn
187	ListQueues(context.Context, *taskspb.ListQueuesRequest, ...gax.CallOption) *QueueIterator
188	GetQueue(context.Context, *taskspb.GetQueueRequest, ...gax.CallOption) (*taskspb.Queue, error)
189	CreateQueue(context.Context, *taskspb.CreateQueueRequest, ...gax.CallOption) (*taskspb.Queue, error)
190	UpdateQueue(context.Context, *taskspb.UpdateQueueRequest, ...gax.CallOption) (*taskspb.Queue, error)
191	DeleteQueue(context.Context, *taskspb.DeleteQueueRequest, ...gax.CallOption) error
192	PurgeQueue(context.Context, *taskspb.PurgeQueueRequest, ...gax.CallOption) (*taskspb.Queue, error)
193	PauseQueue(context.Context, *taskspb.PauseQueueRequest, ...gax.CallOption) (*taskspb.Queue, error)
194	ResumeQueue(context.Context, *taskspb.ResumeQueueRequest, ...gax.CallOption) (*taskspb.Queue, error)
195	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
196	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
197	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
198	ListTasks(context.Context, *taskspb.ListTasksRequest, ...gax.CallOption) *TaskIterator
199	GetTask(context.Context, *taskspb.GetTaskRequest, ...gax.CallOption) (*taskspb.Task, error)
200	CreateTask(context.Context, *taskspb.CreateTaskRequest, ...gax.CallOption) (*taskspb.Task, error)
201	DeleteTask(context.Context, *taskspb.DeleteTaskRequest, ...gax.CallOption) error
202	RunTask(context.Context, *taskspb.RunTaskRequest, ...gax.CallOption) (*taskspb.Task, error)
203}
204
205// Client is a client for interacting with Cloud Tasks API.
206// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
207//
208// Cloud Tasks allows developers to manage the execution of background
209// work in their applications.
210type Client struct {
211	// The internal transport-dependent client.
212	internalClient internalClient
213
214	// The call options for this service.
215	CallOptions *CallOptions
216}
217
218// Wrapper methods routed to the internal client.
219
220// Close closes the connection to the API service. The user should invoke this when
221// the client is no longer required.
222func (c *Client) Close() error {
223	return c.internalClient.Close()
224}
225
226// setGoogleClientInfo sets the name and version of the application in
227// the `x-goog-api-client` header passed on each request. Intended for
228// use by Google-written clients.
229func (c *Client) setGoogleClientInfo(keyval ...string) {
230	c.internalClient.setGoogleClientInfo(keyval...)
231}
232
233// Connection returns a connection to the API service.
234//
235// Deprecated.
236func (c *Client) Connection() *grpc.ClientConn {
237	return c.internalClient.Connection()
238}
239
240// ListQueues lists queues.
241//
242// Queues are returned in lexicographical order.
243func (c *Client) ListQueues(ctx context.Context, req *taskspb.ListQueuesRequest, opts ...gax.CallOption) *QueueIterator {
244	return c.internalClient.ListQueues(ctx, req, opts...)
245}
246
247// GetQueue gets a queue.
248func (c *Client) GetQueue(ctx context.Context, req *taskspb.GetQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
249	return c.internalClient.GetQueue(ctx, req, opts...)
250}
251
252// CreateQueue creates a queue.
253//
254// Queues created with this method allow tasks to live for a maximum of 31
255// days. After a task is 31 days old, the task will be deleted regardless of whether
256// it was dispatched or not.
257//
258// WARNING: Using this method may have unintended side effects if you are
259// using an App Engine queue.yaml or queue.xml file to manage your queues.
260// Read
261// Overview of Queue Management and
262// queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
263// this method.
264func (c *Client) CreateQueue(ctx context.Context, req *taskspb.CreateQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
265	return c.internalClient.CreateQueue(ctx, req, opts...)
266}
267
268// UpdateQueue updates a queue.
269//
270// This method creates the queue if it does not exist and updates
271// the queue if it does exist.
272//
273// Queues created with this method allow tasks to live for a maximum of 31
274// days. After a task is 31 days old, the task will be deleted regardless of whether
275// it was dispatched or not.
276//
277// WARNING: Using this method may have unintended side effects if you are
278// using an App Engine queue.yaml or queue.xml file to manage your queues.
279// Read
280// Overview of Queue Management and
281// queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
282// this method.
283func (c *Client) UpdateQueue(ctx context.Context, req *taskspb.UpdateQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
284	return c.internalClient.UpdateQueue(ctx, req, opts...)
285}
286
287// DeleteQueue deletes a queue.
288//
289// This command will delete the queue even if it has tasks in it.
290//
291// Note: If you delete a queue, a queue with the same name can’t be created
292// for 7 days.
293//
294// WARNING: Using this method may have unintended side effects if you are
295// using an App Engine queue.yaml or queue.xml file to manage your queues.
296// Read
297// Overview of Queue Management and
298// queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
299// this method.
300func (c *Client) DeleteQueue(ctx context.Context, req *taskspb.DeleteQueueRequest, opts ...gax.CallOption) error {
301	return c.internalClient.DeleteQueue(ctx, req, opts...)
302}
303
304// PurgeQueue purges a queue by deleting all of its tasks.
305//
306// All tasks created before this method is called are permanently deleted.
307//
308// Purge operations can take up to one minute to take effect. Tasks
309// might be dispatched before the purge takes effect. A purge is irreversible.
310func (c *Client) PurgeQueue(ctx context.Context, req *taskspb.PurgeQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
311	return c.internalClient.PurgeQueue(ctx, req, opts...)
312}
313
314// PauseQueue pauses the queue.
315//
316// If a queue is paused then the system will stop dispatching tasks
317// until the queue is resumed via
318// ResumeQueue. Tasks can still be added
319// when the queue is paused. A queue is paused if its
320// state is PAUSED.
321func (c *Client) PauseQueue(ctx context.Context, req *taskspb.PauseQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
322	return c.internalClient.PauseQueue(ctx, req, opts...)
323}
324
325// ResumeQueue resume a queue.
326//
327// This method resumes a queue after it has been
328// PAUSED or
329// DISABLED. The state of a queue is stored
330// in the queue’s state; after calling this method it
331// will be set to RUNNING.
332//
333// WARNING: Resuming many high-QPS queues at the same time can
334// lead to target overloading. If you are resuming high-QPS
335// queues, follow the 500/50/5 pattern described in
336// Managing Cloud Tasks Scaling
337// Risks (at https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
338func (c *Client) ResumeQueue(ctx context.Context, req *taskspb.ResumeQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
339	return c.internalClient.ResumeQueue(ctx, req, opts...)
340}
341
342// GetIamPolicy gets the access control policy for a Queue.
343// Returns an empty policy if the resource exists and does not have a policy
344// set.
345//
346// Authorization requires the following
347// Google IAM (at https://cloud.google.com/iam) permission on the specified
348// resource parent:
349//
350//   cloudtasks.queues.getIamPolicy
351func (c *Client) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
352	return c.internalClient.GetIamPolicy(ctx, req, opts...)
353}
354
355// SetIamPolicy sets the access control policy for a Queue. Replaces any existing
356// policy.
357//
358// Note: The Cloud Console does not check queue-level IAM permissions yet.
359// Project-level permissions are required to use the Cloud Console.
360//
361// Authorization requires the following
362// Google IAM (at https://cloud.google.com/iam) permission on the specified
363// resource parent:
364//
365//   cloudtasks.queues.setIamPolicy
366func (c *Client) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
367	return c.internalClient.SetIamPolicy(ctx, req, opts...)
368}
369
370// TestIamPermissions returns permissions that a caller has on a Queue.
371// If the resource does not exist, this will return an empty set of
372// permissions, not a NOT_FOUND error.
373//
374// Note: This operation is designed to be used for building permission-aware
375// UIs and command-line tools, not for authorization checking. This operation
376// may “fail open” without warning.
377func (c *Client) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
378	return c.internalClient.TestIamPermissions(ctx, req, opts...)
379}
380
381// ListTasks lists the tasks in a queue.
382//
383// By default, only the BASIC view is retrieved
384// due to performance considerations;
385// response_view controls the
386// subset of information which is returned.
387//
388// The tasks may be returned in any order. The ordering may change at any
389// time.
390func (c *Client) ListTasks(ctx context.Context, req *taskspb.ListTasksRequest, opts ...gax.CallOption) *TaskIterator {
391	return c.internalClient.ListTasks(ctx, req, opts...)
392}
393
394// GetTask gets a task.
395func (c *Client) GetTask(ctx context.Context, req *taskspb.GetTaskRequest, opts ...gax.CallOption) (*taskspb.Task, error) {
396	return c.internalClient.GetTask(ctx, req, opts...)
397}
398
399// CreateTask creates a task and adds it to a queue.
400//
401// Tasks cannot be updated after creation; there is no UpdateTask command.
402//
403//   The maximum task size is 100KB.
404func (c *Client) CreateTask(ctx context.Context, req *taskspb.CreateTaskRequest, opts ...gax.CallOption) (*taskspb.Task, error) {
405	return c.internalClient.CreateTask(ctx, req, opts...)
406}
407
408// DeleteTask deletes a task.
409//
410// A task can be deleted if it is scheduled or dispatched. A task
411// cannot be deleted if it has executed successfully or permanently
412// failed.
413func (c *Client) DeleteTask(ctx context.Context, req *taskspb.DeleteTaskRequest, opts ...gax.CallOption) error {
414	return c.internalClient.DeleteTask(ctx, req, opts...)
415}
416
417// RunTask forces a task to run now.
418//
419// When this method is called, Cloud Tasks will dispatch the task, even if
420// the task is already running, the queue has reached its RateLimits or
421// is PAUSED.
422//
423// This command is meant to be used for manual debugging. For
424// example, RunTask can be used to retry a failed
425// task after a fix has been made or to manually force a task to be
426// dispatched now.
427//
428// The dispatched task is returned. That is, the task that is returned
429// contains the status after the task is dispatched but
430// before the task is received by its target.
431//
432// If Cloud Tasks receives a successful response from the task’s
433// target, then the task will be deleted; otherwise the task’s
434// schedule_time will be reset to the time that
435// RunTask was called plus the retry delay specified
436// in the queue’s RetryConfig.
437//
438// RunTask returns
439// NOT_FOUND when it is called on a
440// task that has already succeeded or permanently failed.
441func (c *Client) RunTask(ctx context.Context, req *taskspb.RunTaskRequest, opts ...gax.CallOption) (*taskspb.Task, error) {
442	return c.internalClient.RunTask(ctx, req, opts...)
443}
444
445// gRPCClient is a client for interacting with Cloud Tasks API over gRPC transport.
446//
447// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
448type gRPCClient struct {
449	// Connection pool of gRPC connections to the service.
450	connPool gtransport.ConnPool
451
452	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
453	disableDeadlines bool
454
455	// Points back to the CallOptions field of the containing Client
456	CallOptions **CallOptions
457
458	// The gRPC API client.
459	client taskspb.CloudTasksClient
460
461	// The x-goog-* metadata to be sent with each request.
462	xGoogMetadata metadata.MD
463}
464
465// NewClient creates a new cloud tasks client based on gRPC.
466// The returned client must be Closed when it is done being used to clean up its underlying connections.
467//
468// Cloud Tasks allows developers to manage the execution of background
469// work in their applications.
470func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
471	clientOpts := defaultGRPCClientOptions()
472	if newClientHook != nil {
473		hookOpts, err := newClientHook(ctx, clientHookParams{})
474		if err != nil {
475			return nil, err
476		}
477		clientOpts = append(clientOpts, hookOpts...)
478	}
479
480	disableDeadlines, err := checkDisableDeadlines()
481	if err != nil {
482		return nil, err
483	}
484
485	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
486	if err != nil {
487		return nil, err
488	}
489	client := Client{CallOptions: defaultCallOptions()}
490
491	c := &gRPCClient{
492		connPool:         connPool,
493		disableDeadlines: disableDeadlines,
494		client:           taskspb.NewCloudTasksClient(connPool),
495		CallOptions:      &client.CallOptions,
496	}
497	c.setGoogleClientInfo()
498
499	client.internalClient = c
500
501	return &client, nil
502}
503
504// Connection returns a connection to the API service.
505//
506// Deprecated.
507func (c *gRPCClient) Connection() *grpc.ClientConn {
508	return c.connPool.Conn()
509}
510
511// setGoogleClientInfo sets the name and version of the application in
512// the `x-goog-api-client` header passed on each request. Intended for
513// use by Google-written clients.
514func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
515	kv := append([]string{"gl-go", versionGo()}, keyval...)
516	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
517	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
518}
519
520// Close closes the connection to the API service. The user should invoke this when
521// the client is no longer required.
522func (c *gRPCClient) Close() error {
523	return c.connPool.Close()
524}
525
526func (c *gRPCClient) ListQueues(ctx context.Context, req *taskspb.ListQueuesRequest, opts ...gax.CallOption) *QueueIterator {
527	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
528	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
529	opts = append((*c.CallOptions).ListQueues[0:len((*c.CallOptions).ListQueues):len((*c.CallOptions).ListQueues)], opts...)
530	it := &QueueIterator{}
531	req = proto.Clone(req).(*taskspb.ListQueuesRequest)
532	it.InternalFetch = func(pageSize int, pageToken string) ([]*taskspb.Queue, string, error) {
533		var resp *taskspb.ListQueuesResponse
534		req.PageToken = pageToken
535		if pageSize > math.MaxInt32 {
536			req.PageSize = math.MaxInt32
537		} else {
538			req.PageSize = int32(pageSize)
539		}
540		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
541			var err error
542			resp, err = c.client.ListQueues(ctx, req, settings.GRPC...)
543			return err
544		}, opts...)
545		if err != nil {
546			return nil, "", err
547		}
548
549		it.Response = resp
550		return resp.GetQueues(), resp.GetNextPageToken(), nil
551	}
552	fetch := func(pageSize int, pageToken string) (string, error) {
553		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
554		if err != nil {
555			return "", err
556		}
557		it.items = append(it.items, items...)
558		return nextPageToken, nil
559	}
560	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
561	it.pageInfo.MaxSize = int(req.GetPageSize())
562	it.pageInfo.Token = req.GetPageToken()
563	return it
564}
565
566func (c *gRPCClient) GetQueue(ctx context.Context, req *taskspb.GetQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
567	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
568		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
569		defer cancel()
570		ctx = cctx
571	}
572	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
573	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
574	opts = append((*c.CallOptions).GetQueue[0:len((*c.CallOptions).GetQueue):len((*c.CallOptions).GetQueue)], opts...)
575	var resp *taskspb.Queue
576	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
577		var err error
578		resp, err = c.client.GetQueue(ctx, req, settings.GRPC...)
579		return err
580	}, opts...)
581	if err != nil {
582		return nil, err
583	}
584	return resp, nil
585}
586
587func (c *gRPCClient) CreateQueue(ctx context.Context, req *taskspb.CreateQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
588	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
589		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
590		defer cancel()
591		ctx = cctx
592	}
593	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
594	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
595	opts = append((*c.CallOptions).CreateQueue[0:len((*c.CallOptions).CreateQueue):len((*c.CallOptions).CreateQueue)], opts...)
596	var resp *taskspb.Queue
597	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
598		var err error
599		resp, err = c.client.CreateQueue(ctx, req, settings.GRPC...)
600		return err
601	}, opts...)
602	if err != nil {
603		return nil, err
604	}
605	return resp, nil
606}
607
608func (c *gRPCClient) UpdateQueue(ctx context.Context, req *taskspb.UpdateQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
609	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
610		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
611		defer cancel()
612		ctx = cctx
613	}
614	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "queue.name", url.QueryEscape(req.GetQueue().GetName())))
615	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
616	opts = append((*c.CallOptions).UpdateQueue[0:len((*c.CallOptions).UpdateQueue):len((*c.CallOptions).UpdateQueue)], opts...)
617	var resp *taskspb.Queue
618	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
619		var err error
620		resp, err = c.client.UpdateQueue(ctx, req, settings.GRPC...)
621		return err
622	}, opts...)
623	if err != nil {
624		return nil, err
625	}
626	return resp, nil
627}
628
629func (c *gRPCClient) DeleteQueue(ctx context.Context, req *taskspb.DeleteQueueRequest, opts ...gax.CallOption) error {
630	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
631		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
632		defer cancel()
633		ctx = cctx
634	}
635	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
636	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
637	opts = append((*c.CallOptions).DeleteQueue[0:len((*c.CallOptions).DeleteQueue):len((*c.CallOptions).DeleteQueue)], opts...)
638	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
639		var err error
640		_, err = c.client.DeleteQueue(ctx, req, settings.GRPC...)
641		return err
642	}, opts...)
643	return err
644}
645
646func (c *gRPCClient) PurgeQueue(ctx context.Context, req *taskspb.PurgeQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
647	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
648		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
649		defer cancel()
650		ctx = cctx
651	}
652	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
653	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
654	opts = append((*c.CallOptions).PurgeQueue[0:len((*c.CallOptions).PurgeQueue):len((*c.CallOptions).PurgeQueue)], opts...)
655	var resp *taskspb.Queue
656	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
657		var err error
658		resp, err = c.client.PurgeQueue(ctx, req, settings.GRPC...)
659		return err
660	}, opts...)
661	if err != nil {
662		return nil, err
663	}
664	return resp, nil
665}
666
667func (c *gRPCClient) PauseQueue(ctx context.Context, req *taskspb.PauseQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
668	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
669		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
670		defer cancel()
671		ctx = cctx
672	}
673	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
674	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
675	opts = append((*c.CallOptions).PauseQueue[0:len((*c.CallOptions).PauseQueue):len((*c.CallOptions).PauseQueue)], opts...)
676	var resp *taskspb.Queue
677	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
678		var err error
679		resp, err = c.client.PauseQueue(ctx, req, settings.GRPC...)
680		return err
681	}, opts...)
682	if err != nil {
683		return nil, err
684	}
685	return resp, nil
686}
687
688func (c *gRPCClient) ResumeQueue(ctx context.Context, req *taskspb.ResumeQueueRequest, opts ...gax.CallOption) (*taskspb.Queue, error) {
689	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
690		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
691		defer cancel()
692		ctx = cctx
693	}
694	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
695	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
696	opts = append((*c.CallOptions).ResumeQueue[0:len((*c.CallOptions).ResumeQueue):len((*c.CallOptions).ResumeQueue)], opts...)
697	var resp *taskspb.Queue
698	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
699		var err error
700		resp, err = c.client.ResumeQueue(ctx, req, settings.GRPC...)
701		return err
702	}, opts...)
703	if err != nil {
704		return nil, err
705	}
706	return resp, nil
707}
708
709func (c *gRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
710	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
711		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
712		defer cancel()
713		ctx = cctx
714	}
715	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
716	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
717	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
718	var resp *iampb.Policy
719	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
720		var err error
721		resp, err = c.client.GetIamPolicy(ctx, req, settings.GRPC...)
722		return err
723	}, opts...)
724	if err != nil {
725		return nil, err
726	}
727	return resp, nil
728}
729
730func (c *gRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
731	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
732		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
733		defer cancel()
734		ctx = cctx
735	}
736	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
737	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
738	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
739	var resp *iampb.Policy
740	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
741		var err error
742		resp, err = c.client.SetIamPolicy(ctx, req, settings.GRPC...)
743		return err
744	}, opts...)
745	if err != nil {
746		return nil, err
747	}
748	return resp, nil
749}
750
751func (c *gRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
752	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
753		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
754		defer cancel()
755		ctx = cctx
756	}
757	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
758	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
759	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
760	var resp *iampb.TestIamPermissionsResponse
761	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
762		var err error
763		resp, err = c.client.TestIamPermissions(ctx, req, settings.GRPC...)
764		return err
765	}, opts...)
766	if err != nil {
767		return nil, err
768	}
769	return resp, nil
770}
771
772func (c *gRPCClient) ListTasks(ctx context.Context, req *taskspb.ListTasksRequest, opts ...gax.CallOption) *TaskIterator {
773	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
774	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
775	opts = append((*c.CallOptions).ListTasks[0:len((*c.CallOptions).ListTasks):len((*c.CallOptions).ListTasks)], opts...)
776	it := &TaskIterator{}
777	req = proto.Clone(req).(*taskspb.ListTasksRequest)
778	it.InternalFetch = func(pageSize int, pageToken string) ([]*taskspb.Task, string, error) {
779		var resp *taskspb.ListTasksResponse
780		req.PageToken = pageToken
781		if pageSize > math.MaxInt32 {
782			req.PageSize = math.MaxInt32
783		} else {
784			req.PageSize = int32(pageSize)
785		}
786		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
787			var err error
788			resp, err = c.client.ListTasks(ctx, req, settings.GRPC...)
789			return err
790		}, opts...)
791		if err != nil {
792			return nil, "", err
793		}
794
795		it.Response = resp
796		return resp.GetTasks(), resp.GetNextPageToken(), nil
797	}
798	fetch := func(pageSize int, pageToken string) (string, error) {
799		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
800		if err != nil {
801			return "", err
802		}
803		it.items = append(it.items, items...)
804		return nextPageToken, nil
805	}
806	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
807	it.pageInfo.MaxSize = int(req.GetPageSize())
808	it.pageInfo.Token = req.GetPageToken()
809	return it
810}
811
812func (c *gRPCClient) GetTask(ctx context.Context, req *taskspb.GetTaskRequest, opts ...gax.CallOption) (*taskspb.Task, error) {
813	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
814		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
815		defer cancel()
816		ctx = cctx
817	}
818	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
819	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
820	opts = append((*c.CallOptions).GetTask[0:len((*c.CallOptions).GetTask):len((*c.CallOptions).GetTask)], opts...)
821	var resp *taskspb.Task
822	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
823		var err error
824		resp, err = c.client.GetTask(ctx, req, settings.GRPC...)
825		return err
826	}, opts...)
827	if err != nil {
828		return nil, err
829	}
830	return resp, nil
831}
832
833func (c *gRPCClient) CreateTask(ctx context.Context, req *taskspb.CreateTaskRequest, opts ...gax.CallOption) (*taskspb.Task, error) {
834	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
835		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
836		defer cancel()
837		ctx = cctx
838	}
839	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
840	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
841	opts = append((*c.CallOptions).CreateTask[0:len((*c.CallOptions).CreateTask):len((*c.CallOptions).CreateTask)], opts...)
842	var resp *taskspb.Task
843	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
844		var err error
845		resp, err = c.client.CreateTask(ctx, req, settings.GRPC...)
846		return err
847	}, opts...)
848	if err != nil {
849		return nil, err
850	}
851	return resp, nil
852}
853
854func (c *gRPCClient) DeleteTask(ctx context.Context, req *taskspb.DeleteTaskRequest, opts ...gax.CallOption) error {
855	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
856		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
857		defer cancel()
858		ctx = cctx
859	}
860	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
861	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
862	opts = append((*c.CallOptions).DeleteTask[0:len((*c.CallOptions).DeleteTask):len((*c.CallOptions).DeleteTask)], opts...)
863	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
864		var err error
865		_, err = c.client.DeleteTask(ctx, req, settings.GRPC...)
866		return err
867	}, opts...)
868	return err
869}
870
871func (c *gRPCClient) RunTask(ctx context.Context, req *taskspb.RunTaskRequest, opts ...gax.CallOption) (*taskspb.Task, error) {
872	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
873		cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
874		defer cancel()
875		ctx = cctx
876	}
877	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
878	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
879	opts = append((*c.CallOptions).RunTask[0:len((*c.CallOptions).RunTask):len((*c.CallOptions).RunTask)], opts...)
880	var resp *taskspb.Task
881	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
882		var err error
883		resp, err = c.client.RunTask(ctx, req, settings.GRPC...)
884		return err
885	}, opts...)
886	if err != nil {
887		return nil, err
888	}
889	return resp, nil
890}
891
892// QueueIterator manages a stream of *taskspb.Queue.
893type QueueIterator struct {
894	items    []*taskspb.Queue
895	pageInfo *iterator.PageInfo
896	nextFunc func() error
897
898	// Response is the raw response for the current page.
899	// It must be cast to the RPC response type.
900	// Calling Next() or InternalFetch() updates this value.
901	Response interface{}
902
903	// InternalFetch is for use by the Google Cloud Libraries only.
904	// It is not part of the stable interface of this package.
905	//
906	// InternalFetch returns results from a single call to the underlying RPC.
907	// The number of results is no greater than pageSize.
908	// If there are no more results, nextPageToken is empty and err is nil.
909	InternalFetch func(pageSize int, pageToken string) (results []*taskspb.Queue, nextPageToken string, err error)
910}
911
912// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
913func (it *QueueIterator) PageInfo() *iterator.PageInfo {
914	return it.pageInfo
915}
916
917// Next returns the next result. Its second return value is iterator.Done if there are no more
918// results. Once Next returns Done, all subsequent calls will return Done.
919func (it *QueueIterator) Next() (*taskspb.Queue, error) {
920	var item *taskspb.Queue
921	if err := it.nextFunc(); err != nil {
922		return item, err
923	}
924	item = it.items[0]
925	it.items = it.items[1:]
926	return item, nil
927}
928
929func (it *QueueIterator) bufLen() int {
930	return len(it.items)
931}
932
933func (it *QueueIterator) takeBuf() interface{} {
934	b := it.items
935	it.items = nil
936	return b
937}
938
939// TaskIterator manages a stream of *taskspb.Task.
940type TaskIterator struct {
941	items    []*taskspb.Task
942	pageInfo *iterator.PageInfo
943	nextFunc func() error
944
945	// Response is the raw response for the current page.
946	// It must be cast to the RPC response type.
947	// Calling Next() or InternalFetch() updates this value.
948	Response interface{}
949
950	// InternalFetch is for use by the Google Cloud Libraries only.
951	// It is not part of the stable interface of this package.
952	//
953	// InternalFetch returns results from a single call to the underlying RPC.
954	// The number of results is no greater than pageSize.
955	// If there are no more results, nextPageToken is empty and err is nil.
956	InternalFetch func(pageSize int, pageToken string) (results []*taskspb.Task, nextPageToken string, err error)
957}
958
959// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
960func (it *TaskIterator) PageInfo() *iterator.PageInfo {
961	return it.pageInfo
962}
963
964// Next returns the next result. Its second return value is iterator.Done if there are no more
965// results. Once Next returns Done, all subsequent calls will return Done.
966func (it *TaskIterator) Next() (*taskspb.Task, error) {
967	var item *taskspb.Task
968	if err := it.nextFunc(); err != nil {
969		return item, err
970	}
971	item = it.items[0]
972	it.items = it.items[1:]
973	return item, nil
974}
975
976func (it *TaskIterator) bufLen() int {
977	return len(it.items)
978}
979
980func (it *TaskIterator) takeBuf() interface{} {
981	b := it.items
982	it.items = nil
983	return b
984}
985