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