lib/google/cloud/tasks/v2beta2/cloud_tasks_client.rb in google-cloud-tasks-0.1.0 vs lib/google/cloud/tasks/v2beta2/cloud_tasks_client.rb in google-cloud-tasks-0.2.0
- old
+ new
@@ -23,11 +23,11 @@
require "pathname"
require "google/gax"
require "google/cloud/tasks/v2beta2/cloudtasks_pb"
-require "google/cloud/tasks/credentials"
+require "google/cloud/tasks/v2beta2/credentials"
module Google
module Cloud
module Tasks
module V2beta2
@@ -43,10 +43,13 @@
SERVICE_ADDRESS = "cloudtasks.googleapis.com".freeze
# The default port of the service.
DEFAULT_SERVICE_PORT = 443
+ # The default set of gRPC interceptors.
+ GRPC_INTERCEPTORS = []
+
DEFAULT_TIMEOUT = 30
PAGE_DESCRIPTORS = {
"list_queues" => Google::Gax::PageDescriptor.new(
"page_token",
@@ -65,10 +68,16 @@
ALL_SCOPES = [
"https://www.googleapis.com/auth/cloud-platform"
].freeze
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
+ "projects/{project}"
+ )
+
+ private_constant :PROJECT_PATH_TEMPLATE
+
LOCATION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
"projects/{project}/locations/{location}"
)
private_constant :LOCATION_PATH_TEMPLATE
@@ -83,10 +92,19 @@
"projects/{project}/locations/{location}/queues/{queue}/tasks/{task}"
)
private_constant :TASK_PATH_TEMPLATE
+ # Returns a fully-qualified project resource name string.
+ # @param project [String]
+ # @return [String]
+ def self.project_path project
+ PROJECT_PATH_TEMPLATE.render(
+ :"project" => project
+ )
+ end
+
# Returns a fully-qualified location resource name string.
# @param project [String]
# @param location [String]
# @return [String]
def self.location_path project, location
@@ -146,27 +164,34 @@
# Google::Gax#construct_settings for the structure of
# this data. Falls back to the default config if not specified
# or the specified config is missing data points.
# @param timeout [Numeric]
# The default timeout, in seconds, for calls made through this client.
+ # @param metadata [Hash]
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
+ # @param exception_transformer [Proc]
+ # An optional proc that intercepts any exceptions raised during an API call to inject
+ # custom error handling.
def initialize \
credentials: nil,
scopes: ALL_SCOPES,
client_config: {},
timeout: DEFAULT_TIMEOUT,
+ metadata: nil,
+ exception_transformer: nil,
lib_name: nil,
lib_version: ""
# These require statements are intentionally placed here to initialize
# the gRPC module only when it's required.
# See https://github.com/googleapis/toolkit/issues/446
require "google/gax/grpc"
require "google/cloud/tasks/v2beta2/cloudtasks_services_pb"
- credentials ||= Google::Cloud::Tasks::Credentials.default
+ credentials ||= Google::Cloud::Tasks::V2beta2::Credentials.default
if credentials.is_a?(String) || credentials.is_a?(Hash)
- updater_proc = Google::Cloud::Tasks::Credentials.new(credentials).updater_proc
+ updater_proc = Google::Cloud::Tasks::V2beta2::Credentials.new(credentials).updater_proc
end
if credentials.is_a?(GRPC::Core::Channel)
channel = credentials
end
if credentials.is_a?(GRPC::Core::ChannelCredentials)
@@ -186,10 +211,11 @@
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
google_api_client << " grpc/#{GRPC::VERSION}"
google_api_client.freeze
headers = { :"x-goog-api-client" => google_api_client }
+ headers.merge!(metadata) unless metadata.nil?
client_config_file = Pathname.new(__dir__).join(
"cloud_tasks_client_config.json"
)
defaults = client_config_file.open do |f|
Google::Gax.construct_settings(
@@ -198,106 +224,188 @@
client_config,
Google::Gax::Grpc::STATUS_CODE_NAMES,
timeout,
page_descriptors: PAGE_DESCRIPTORS,
errors: Google::Gax::Grpc::API_ERRORS,
- kwargs: headers
+ metadata: headers
)
end
# Allow overriding the service path/port in subclasses.
service_path = self.class::SERVICE_ADDRESS
port = self.class::DEFAULT_SERVICE_PORT
+ interceptors = self.class::GRPC_INTERCEPTORS
@cloud_tasks_stub = Google::Gax::Grpc.create_stub(
service_path,
port,
chan_creds: chan_creds,
channel: channel,
updater_proc: updater_proc,
scopes: scopes,
+ interceptors: interceptors,
&Google::Cloud::Tasks::V2beta2::CloudTasks::Stub.method(:new)
)
@list_queues = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:list_queues),
- defaults["list_queues"]
+ defaults["list_queues"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@get_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:get_queue),
- defaults["get_queue"]
+ defaults["get_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@create_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:create_queue),
- defaults["create_queue"]
+ defaults["create_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@update_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:update_queue),
- defaults["update_queue"]
+ defaults["update_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'queue.name' => request.queue.name}
+ end
)
@delete_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:delete_queue),
- defaults["delete_queue"]
+ defaults["delete_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@purge_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:purge_queue),
- defaults["purge_queue"]
+ defaults["purge_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@pause_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:pause_queue),
- defaults["pause_queue"]
+ defaults["pause_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@resume_queue = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:resume_queue),
- defaults["resume_queue"]
+ defaults["resume_queue"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@get_iam_policy = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:get_iam_policy),
- defaults["get_iam_policy"]
+ defaults["get_iam_policy"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'resource' => request.resource}
+ end
)
@set_iam_policy = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:set_iam_policy),
- defaults["set_iam_policy"]
+ defaults["set_iam_policy"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'resource' => request.resource}
+ end
)
@test_iam_permissions = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:test_iam_permissions),
- defaults["test_iam_permissions"]
+ defaults["test_iam_permissions"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'resource' => request.resource}
+ end
)
@list_tasks = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:list_tasks),
- defaults["list_tasks"]
+ defaults["list_tasks"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@get_task = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:get_task),
- defaults["get_task"]
+ defaults["get_task"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@create_task = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:create_task),
- defaults["create_task"]
+ defaults["create_task"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@delete_task = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:delete_task),
- defaults["delete_task"]
+ defaults["delete_task"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@lease_tasks = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:lease_tasks),
- defaults["lease_tasks"]
+ defaults["lease_tasks"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@acknowledge_task = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:acknowledge_task),
- defaults["acknowledge_task"]
+ defaults["acknowledge_task"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@renew_lease = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:renew_lease),
- defaults["renew_lease"]
+ defaults["renew_lease"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@cancel_lease = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:cancel_lease),
- defaults["cancel_lease"]
+ defaults["cancel_lease"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@run_task = Google::Gax.create_api_call(
@cloud_tasks_stub.method(:run_task),
- defaults["run_task"]
+ defaults["run_task"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
end
# Service calls
@@ -328,10 +436,13 @@
# performed per-page, this determines the maximum number of
# resources in a page.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::Tasks::V2beta2::Queue>]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Gax::PagedEnumerable<Google::Cloud::Tasks::V2beta2::Queue>]
# An enumerable of Google::Cloud::Tasks::V2beta2::Queue instances.
# See Google::Gax::PagedEnumerable documentation for other
# operations such as per-page iteration or access to the response
# object.
@@ -357,18 +468,19 @@
def list_queues \
parent,
filter: nil,
page_size: nil,
- options: nil
+ options: nil,
+ &block
req = {
parent: parent,
filter: filter,
page_size: page_size
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::ListQueuesRequest)
- @list_queues.call(req, options)
+ @list_queues.call(req, options, &block)
end
# Gets a queue.
#
# @param name [String]
@@ -377,10 +489,13 @@
# The resource name of the queue. For example:
# +projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID+
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Queue]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Queue]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -388,16 +503,17 @@
# formatted_name = Google::Cloud::Tasks::V2beta2::CloudTasksClient.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
# response = cloud_tasks_client.get_queue(formatted_name)
def get_queue \
name,
- options: nil
+ options: nil,
+ &block
req = {
name: name
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::GetQueueRequest)
- @get_queue.call(req, options)
+ @get_queue.call(req, options, &block)
end
# Creates a queue.
#
# Queues created with this method allow tasks to live for a maximum of 31
@@ -428,10 +544,13 @@
# A hash of the same form as `Google::Cloud::Tasks::V2beta2::Queue`
# can also be provided.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Queue]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Queue]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -443,17 +562,18 @@
# response = cloud_tasks_client.create_queue(formatted_parent, queue)
def create_queue \
parent,
queue,
- options: nil
+ options: nil,
+ &block
req = {
parent: parent,
queue: queue
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::CreateQueueRequest)
- @create_queue.call(req, options)
+ @create_queue.call(req, options, &block)
end
# Updates a queue.
#
# This method creates the queue if it does not exist and updates
@@ -488,10 +608,13 @@
# A hash of the same form as `Google::Protobuf::FieldMask`
# can also be provided.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Queue]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Queue]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -502,17 +625,18 @@
# response = cloud_tasks_client.update_queue(queue)
def update_queue \
queue,
update_mask: nil,
- options: nil
+ options: nil,
+ &block
req = {
queue: queue,
update_mask: update_mask
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::UpdateQueueRequest)
- @update_queue.call(req, options)
+ @update_queue.call(req, options, &block)
end
# Deletes a queue.
#
# This command will delete the queue even if it has tasks in it.
@@ -532,26 +656,30 @@
# The queue name. For example:
# +projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID+
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result []
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
# cloud_tasks_client = Google::Cloud::Tasks::V2beta2.new
# formatted_name = Google::Cloud::Tasks::V2beta2::CloudTasksClient.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
# cloud_tasks_client.delete_queue(formatted_name)
def delete_queue \
name,
- options: nil
+ options: nil,
+ &block
req = {
name: name
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::DeleteQueueRequest)
- @delete_queue.call(req, options)
+ @delete_queue.call(req, options, &block)
nil
end
# Purges a queue by deleting all of its tasks.
#
@@ -566,10 +694,13 @@
# The queue name. For example:
# +projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID+
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Queue]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Queue]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -577,16 +708,17 @@
# formatted_name = Google::Cloud::Tasks::V2beta2::CloudTasksClient.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
# response = cloud_tasks_client.purge_queue(formatted_name)
def purge_queue \
name,
- options: nil
+ options: nil,
+ &block
req = {
name: name
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::PurgeQueueRequest)
- @purge_queue.call(req, options)
+ @purge_queue.call(req, options, &block)
end
# Pauses the queue.
#
# If a queue is paused then the system will stop dispatching tasks
@@ -601,10 +733,13 @@
# The queue name. For example:
# +projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID+
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Queue]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Queue]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -612,16 +747,17 @@
# formatted_name = Google::Cloud::Tasks::V2beta2::CloudTasksClient.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
# response = cloud_tasks_client.pause_queue(formatted_name)
def pause_queue \
name,
- options: nil
+ options: nil,
+ &block
req = {
name: name
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::PauseQueueRequest)
- @pause_queue.call(req, options)
+ @pause_queue.call(req, options, &block)
end
# Resume a queue.
#
# This method resumes a queue after it has been
@@ -641,10 +777,13 @@
# The queue name. For example:
# +projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID+
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Queue]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Queue]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -652,16 +791,17 @@
# formatted_name = Google::Cloud::Tasks::V2beta2::CloudTasksClient.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
# response = cloud_tasks_client.resume_queue(formatted_name)
def resume_queue \
name,
- options: nil
+ options: nil,
+ &block
req = {
name: name
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::ResumeQueueRequest)
- @resume_queue.call(req, options)
+ @resume_queue.call(req, options, &block)
end
# Gets the access control policy for a {Google::Cloud::Tasks::V2beta2::Queue Queue}.
# Returns an empty policy if the resource exists and does not have a policy
# set.
@@ -676,10 +816,13 @@
# +resource+ is usually specified as a path. For example, a Project
# resource is specified as +projects/{project}+.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Iam::V1::Policy]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Iam::V1::Policy]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -687,16 +830,17 @@
# formatted_resource = Google::Cloud::Tasks::V2beta2::CloudTasksClient.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
# response = cloud_tasks_client.get_iam_policy(formatted_resource)
def get_iam_policy \
resource,
- options: nil
+ options: nil,
+ &block
req = {
resource: resource
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest)
- @get_iam_policy.call(req, options)
+ @get_iam_policy.call(req, options, &block)
end
# Sets the access control policy for a {Google::Cloud::Tasks::V2beta2::Queue Queue}. Replaces any existing
# policy.
#
@@ -720,10 +864,13 @@
# A hash of the same form as `Google::Iam::V1::Policy`
# can also be provided.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Iam::V1::Policy]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Iam::V1::Policy]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -735,17 +882,18 @@
# response = cloud_tasks_client.set_iam_policy(formatted_resource, policy)
def set_iam_policy \
resource,
policy,
- options: nil
+ options: nil,
+ &block
req = {
resource: resource,
policy: policy
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest)
- @set_iam_policy.call(req, options)
+ @set_iam_policy.call(req, options, &block)
end
# Returns permissions that a caller has on a {Google::Cloud::Tasks::V2beta2::Queue Queue}.
# If the resource does not exist, this will return an empty set of
# permissions, not a {Google::Rpc::Code::NOT_FOUND NOT_FOUND} error.
@@ -764,10 +912,13 @@
# information see
# [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Iam::V1::TestIamPermissionsResponse]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Iam::V1::TestIamPermissionsResponse]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -779,17 +930,18 @@
# response = cloud_tasks_client.test_iam_permissions(formatted_resource, permissions)
def test_iam_permissions \
resource,
permissions,
- options: nil
+ options: nil,
+ &block
req = {
resource: resource,
permissions: permissions
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
- @test_iam_permissions.call(req, options)
+ @test_iam_permissions.call(req, options, &block)
end
# Lists the tasks in a queue.
#
# By default, only the {Google::Cloud::Tasks::V2beta2::Task::View::BASIC BASIC} view is retrieved
@@ -827,10 +979,13 @@
# performed per-page, this determines the maximum number of
# resources in a page.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::Tasks::V2beta2::Task>]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Gax::PagedEnumerable<Google::Cloud::Tasks::V2beta2::Task>]
# An enumerable of Google::Cloud::Tasks::V2beta2::Task instances.
# See Google::Gax::PagedEnumerable documentation for other
# operations such as per-page iteration or access to the response
# object.
@@ -857,19 +1012,20 @@
def list_tasks \
parent,
response_view: nil,
order_by: nil,
page_size: nil,
- options: nil
+ options: nil,
+ &block
req = {
parent: parent,
response_view: response_view,
order_by: order_by,
page_size: page_size
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::ListTasksRequest)
- @list_tasks.call(req, options)
+ @list_tasks.call(req, options, &block)
end
# Gets a task.
#
# @param name [String]
@@ -891,10 +1047,13 @@
# +cloudtasks.tasks.fullView+ [Google IAM](https://cloud.google.com/iam/) permission on the
# {Google::Cloud::Tasks::V2beta2::Task Task} resource.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Task]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Task]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -903,26 +1062,22 @@
# response = cloud_tasks_client.get_task(formatted_name)
def get_task \
name,
response_view: nil,
- options: nil
+ options: nil,
+ &block
req = {
name: name,
response_view: response_view
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::GetTaskRequest)
- @get_task.call(req, options)
+ @get_task.call(req, options, &block)
end
# Creates a task and adds it to a queue.
#
- # To add multiple tasks at the same time, use
- # [HTTP batching](https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch)
- # or the batching documentation for your client library, for example
- # https://developers.google.com/api-client-library/python/guide/batch.
- #
# Tasks cannot be updated after creation; there is no UpdateTask command.
#
# * For [App Engine queues](https://cloud.google.comgoogle.cloud.tasks.v2beta2.AppEngineHttpTarget),
# the maximum task size is 100KB.
# * For [pull queues](https://cloud.google.comgoogle.cloud.tasks.v2beta2.PullTarget), this
@@ -987,10 +1142,13 @@
# +cloudtasks.tasks.fullView+ [Google IAM](https://cloud.google.com/iam/) permission on the
# {Google::Cloud::Tasks::V2beta2::Task Task} resource.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Task]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Task]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -1003,18 +1161,19 @@
def create_task \
parent,
task,
response_view: nil,
- options: nil
+ options: nil,
+ &block
req = {
parent: parent,
task: task,
response_view: response_view
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::CreateTaskRequest)
- @create_task.call(req, options)
+ @create_task.call(req, options, &block)
end
# Deletes a task.
#
# A task can be deleted if it is scheduled or dispatched. A task
@@ -1027,26 +1186,30 @@
# The task name. For example:
# +projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID+
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result []
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
# cloud_tasks_client = Google::Cloud::Tasks::V2beta2.new
# formatted_name = Google::Cloud::Tasks::V2beta2::CloudTasksClient.task_path("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]")
# cloud_tasks_client.delete_task(formatted_name)
def delete_task \
name,
- options: nil
+ options: nil,
+ &block
req = {
name: name
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::DeleteTaskRequest)
- @delete_task.call(req, options)
+ @delete_task.call(req, options, &block)
nil
end
# Leases tasks from a pull queue for
# {Google::Cloud::Tasks::V2beta2::LeaseTasksRequest#lease_duration lease_duration}.
@@ -1087,12 +1250,16 @@
# The maximum lease duration is 1 week.
# +lease_duration+ will be truncated to the nearest second.
# A hash of the same form as `Google::Protobuf::Duration`
# can also be provided.
# @param max_tasks [Integer]
- # The maximum number of tasks to lease. The maximum that can be
- # requested is 1000.
+ # The maximum number of tasks to lease.
+ #
+ # The system will make a best effort to return as close to as
+ # +max_tasks+ as possible.
+ #
+ # The largest that +max_tasks+ can be is 1000.
# @param response_view [Google::Cloud::Tasks::V2beta2::Task::View]
# The response_view specifies which subset of the {Google::Cloud::Tasks::V2beta2::Task Task} will be
# returned.
#
# By default response_view is {Google::Cloud::Tasks::V2beta2::Task::View::BASIC BASIC}; not all
@@ -1135,10 +1302,13 @@
# {Google::Cloud::Tasks::V2beta2::LeaseTasksRequest#filter filter} and the task's
# {Google::Cloud::Tasks::V2beta2::PullMessage#tag tag} will be displayed as empty in Cloud Tasks.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::LeaseTasksResponse]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::LeaseTasksResponse]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -1153,20 +1323,21 @@
parent,
lease_duration,
max_tasks: nil,
response_view: nil,
filter: nil,
- options: nil
+ options: nil,
+ &block
req = {
parent: parent,
lease_duration: lease_duration,
max_tasks: max_tasks,
response_view: response_view,
filter: filter
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::LeaseTasksRequest)
- @lease_tasks.call(req, options)
+ @lease_tasks.call(req, options, &block)
end
# Acknowledges a pull task.
#
# The worker, that is, the entity that
@@ -1179,15 +1350,10 @@
# again. After the task is acknowledged, it will not be returned
# by a later {Google::Cloud::Tasks::V2beta2::CloudTasks::LeaseTasks LeaseTasks},
# {Google::Cloud::Tasks::V2beta2::CloudTasks::GetTask GetTask}, or
# {Google::Cloud::Tasks::V2beta2::CloudTasks::ListTasks ListTasks}.
#
- # To acknowledge multiple tasks at the same time, use
- # [HTTP batching](https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch)
- # or the batching documentation for your client library, for example
- # https://developers.google.com/api-client-library/python/guide/batch.
- #
# @param name [String]
# Required.
#
# The task name. For example:
# +projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID+
@@ -1202,10 +1368,13 @@
# A hash of the same form as `Google::Protobuf::Timestamp`
# can also be provided.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result []
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
# cloud_tasks_client = Google::Cloud::Tasks::V2beta2.new
@@ -1216,17 +1385,18 @@
# cloud_tasks_client.acknowledge_task(formatted_name, schedule_time)
def acknowledge_task \
name,
schedule_time,
- options: nil
+ options: nil,
+ &block
req = {
name: name,
schedule_time: schedule_time
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::AcknowledgeTaskRequest)
- @acknowledge_task.call(req, options)
+ @acknowledge_task.call(req, options, &block)
nil
end
# Renew the current lease of a pull task.
#
@@ -1273,10 +1443,13 @@
# +cloudtasks.tasks.fullView+ [Google IAM](https://cloud.google.com/iam/) permission on the
# {Google::Cloud::Tasks::V2beta2::Task Task} resource.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Task]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Task]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -1293,19 +1466,20 @@
def renew_lease \
name,
schedule_time,
lease_duration,
response_view: nil,
- options: nil
+ options: nil,
+ &block
req = {
name: name,
schedule_time: schedule_time,
lease_duration: lease_duration,
response_view: response_view
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::RenewLeaseRequest)
- @renew_lease.call(req, options)
+ @renew_lease.call(req, options, &block)
end
# Cancel a pull task's lease.
#
# The worker can use this method to cancel a task's lease by
@@ -1342,10 +1516,13 @@
# +cloudtasks.tasks.fullView+ [Google IAM](https://cloud.google.com/iam/) permission on the
# {Google::Cloud::Tasks::V2beta2::Task Task} resource.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Task]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Task]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -1358,18 +1535,19 @@
def cancel_lease \
name,
schedule_time,
response_view: nil,
- options: nil
+ options: nil,
+ &block
req = {
name: name,
schedule_time: schedule_time,
response_view: response_view
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::CancelLeaseRequest)
- @cancel_lease.call(req, options)
+ @cancel_lease.call(req, options, &block)
end
# Forces a task to run now.
#
# When this method is called, Cloud Tasks will dispatch the task, even if
@@ -1417,10 +1595,13 @@
# +cloudtasks.tasks.fullView+ [Google IAM](https://cloud.google.com/iam/) permission on the
# {Google::Cloud::Tasks::V2beta2::Task Task} resource.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
+ # @yield [result, operation] Access the result along with the RPC operation
+ # @yieldparam result [Google::Cloud::Tasks::V2beta2::Task]
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
# @return [Google::Cloud::Tasks::V2beta2::Task]
# @raise [Google::Gax::GaxError] if the RPC is aborted.
# @example
# require "google/cloud/tasks/v2beta2"
#
@@ -1429,16 +1610,17 @@
# response = cloud_tasks_client.run_task(formatted_name)
def run_task \
name,
response_view: nil,
- options: nil
+ options: nil,
+ &block
req = {
name: name,
response_view: response_view
}.delete_if { |_, v| v.nil? }
req = Google::Gax::to_proto(req, Google::Cloud::Tasks::V2beta2::RunTaskRequest)
- @run_task.call(req, options)
+ @run_task.call(req, options, &block)
end
end
end
end
end