Class CloudTasksClient
- java.lang.Object
-
- com.google.cloud.tasks.v2beta2.CloudTasksClient
-
- All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource
,AutoCloseable
@BetaApi @Generated("by gapic-generator-java") public class CloudTasksClient extends Object implements com.google.api.gax.core.BackgroundResource
Service Description: Cloud Tasks allows developers to manage the execution of background work in their applications.This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Queue response = cloudTasksClient.getQueue(name); }
Note: close() needs to be called on the CloudTasksClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of CloudTasksSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library CloudTasksSettings cloudTasksSettings = CloudTasksSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) .build(); CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library CloudTasksSettings cloudTasksSettings = CloudTasksSettings.newBuilder().setEndpoint(myEndpoint).build(); CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library CloudTasksSettings cloudTasksSettings = CloudTasksSettings.newHttpJsonBuilder().build(); CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CloudTasksClient.ListLocationsFixedSizeCollection
static class
CloudTasksClient.ListLocationsPage
static class
CloudTasksClient.ListLocationsPagedResponse
static class
CloudTasksClient.ListQueuesFixedSizeCollection
static class
CloudTasksClient.ListQueuesPage
static class
CloudTasksClient.ListQueuesPagedResponse
static class
CloudTasksClient.ListTasksFixedSizeCollection
static class
CloudTasksClient.ListTasksPage
static class
CloudTasksClient.ListTasksPagedResponse
-
Constructor Summary
Constructors Modifier Constructor Description protected
CloudTasksClient(CloudTasksSettings settings)
Constructs an instance of CloudTasksClient, using the given settings.protected
CloudTasksClient(CloudTasksStub stub)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acknowledgeTask(AcknowledgeTaskRequest request)
Acknowledges a pull task.void
acknowledgeTask(TaskName name, com.google.protobuf.Timestamp scheduleTime)
Acknowledges a pull task.void
acknowledgeTask(String name, com.google.protobuf.Timestamp scheduleTime)
Acknowledges a pull task.com.google.api.gax.rpc.UnaryCallable<AcknowledgeTaskRequest,com.google.protobuf.Empty>
acknowledgeTaskCallable()
Acknowledges a pull task.boolean
awaitTermination(long duration, TimeUnit unit)
BufferTaskResponse
bufferTask(BufferTaskRequest request)
Creates and buffers a new task without the need to explicitly define a Task message.BufferTaskResponse
bufferTask(QueueName queue, String taskId, com.google.api.HttpBody body)
Creates and buffers a new task without the need to explicitly define a Task message.BufferTaskResponse
bufferTask(String queue, String taskId, com.google.api.HttpBody body)
Creates and buffers a new task without the need to explicitly define a Task message.com.google.api.gax.rpc.UnaryCallable<BufferTaskRequest,BufferTaskResponse>
bufferTaskCallable()
Creates and buffers a new task without the need to explicitly define a Task message.Task
cancelLease(CancelLeaseRequest request)
Cancel a pull task's lease.Task
cancelLease(TaskName name, com.google.protobuf.Timestamp scheduleTime)
Cancel a pull task's lease.Task
cancelLease(String name, com.google.protobuf.Timestamp scheduleTime)
Cancel a pull task's lease.com.google.api.gax.rpc.UnaryCallable<CancelLeaseRequest,Task>
cancelLeaseCallable()
Cancel a pull task's lease.void
close()
static CloudTasksClient
create()
Constructs an instance of CloudTasksClient with default settings.static CloudTasksClient
create(CloudTasksSettings settings)
Constructs an instance of CloudTasksClient, using the given settings.static CloudTasksClient
create(CloudTasksStub stub)
Constructs an instance of CloudTasksClient, using the given stub for making calls.Queue
createQueue(CreateQueueRequest request)
Creates a queue.Queue
createQueue(LocationName parent, Queue queue)
Creates a queue.Queue
createQueue(String parent, Queue queue)
Creates a queue.com.google.api.gax.rpc.UnaryCallable<CreateQueueRequest,Queue>
createQueueCallable()
Creates a queue.Task
createTask(CreateTaskRequest request)
Creates a task and adds it to a queue.Task
createTask(QueueName parent, Task task)
Creates a task and adds it to a queue.Task
createTask(String parent, Task task)
Creates a task and adds it to a queue.com.google.api.gax.rpc.UnaryCallable<CreateTaskRequest,Task>
createTaskCallable()
Creates a task and adds it to a queue.void
deleteQueue(DeleteQueueRequest request)
Deletes a queue.void
deleteQueue(QueueName name)
Deletes a queue.void
deleteQueue(String name)
Deletes a queue.com.google.api.gax.rpc.UnaryCallable<DeleteQueueRequest,com.google.protobuf.Empty>
deleteQueueCallable()
Deletes a queue.void
deleteTask(DeleteTaskRequest request)
Deletes a task.void
deleteTask(TaskName name)
Deletes a task.void
deleteTask(String name)
Deletes a task.com.google.api.gax.rpc.UnaryCallable<DeleteTaskRequest,com.google.protobuf.Empty>
deleteTaskCallable()
Deletes a task.com.google.iam.v1.Policy
getIamPolicy(com.google.api.resourcenames.ResourceName resource)
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.iam.v1.Policy
getIamPolicy(QueueName queueName)
com.google.iam.v1.Policy
getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.iam.v1.Policy
getIamPolicy(String resource)
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>
getIamPolicyCallable()
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.cloud.location.Location
getLocation(com.google.cloud.location.GetLocationRequest request)
Gets information about a location.com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.GetLocationRequest,com.google.cloud.location.Location>
getLocationCallable()
Gets information about a location.Queue
getQueue(GetQueueRequest request)
Gets a queue.Queue
getQueue(QueueName name)
Gets a queue.Queue
getQueue(String name)
Gets a queue.com.google.api.gax.rpc.UnaryCallable<GetQueueRequest,Queue>
getQueueCallable()
Gets a queue.CloudTasksSettings
getSettings()
CloudTasksStub
getStub()
Task
getTask(GetTaskRequest request)
Gets a task.Task
getTask(TaskName name)
Gets a task.Task
getTask(String name)
Gets a task.com.google.api.gax.rpc.UnaryCallable<GetTaskRequest,Task>
getTaskCallable()
Gets a task.boolean
isShutdown()
boolean
isTerminated()
LeaseTasksResponse
leaseTasks(LeaseTasksRequest request)
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].LeaseTasksResponse
leaseTasks(QueueName parent, com.google.protobuf.Duration leaseDuration)
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].LeaseTasksResponse
leaseTasks(String parent, com.google.protobuf.Duration leaseDuration)
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].com.google.api.gax.rpc.UnaryCallable<LeaseTasksRequest,LeaseTasksResponse>
leaseTasksCallable()
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].CloudTasksClient.ListLocationsPagedResponse
listLocations(com.google.cloud.location.ListLocationsRequest request)
Lists information about the supported locations for this service.com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,com.google.cloud.location.ListLocationsResponse>
listLocationsCallable()
Lists information about the supported locations for this service.com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,CloudTasksClient.ListLocationsPagedResponse>
listLocationsPagedCallable()
Lists information about the supported locations for this service.CloudTasksClient.ListQueuesPagedResponse
listQueues(ListQueuesRequest request)
Lists queues.CloudTasksClient.ListQueuesPagedResponse
listQueues(LocationName parent)
Lists queues.CloudTasksClient.ListQueuesPagedResponse
listQueues(String parent)
Lists queues.com.google.api.gax.rpc.UnaryCallable<ListQueuesRequest,ListQueuesResponse>
listQueuesCallable()
Lists queues.com.google.api.gax.rpc.UnaryCallable<ListQueuesRequest,CloudTasksClient.ListQueuesPagedResponse>
listQueuesPagedCallable()
Lists queues.CloudTasksClient.ListTasksPagedResponse
listTasks(ListTasksRequest request)
Lists the tasks in a queue.CloudTasksClient.ListTasksPagedResponse
listTasks(QueueName parent)
Lists the tasks in a queue.CloudTasksClient.ListTasksPagedResponse
listTasks(String parent)
Lists the tasks in a queue.com.google.api.gax.rpc.UnaryCallable<ListTasksRequest,ListTasksResponse>
listTasksCallable()
Lists the tasks in a queue.com.google.api.gax.rpc.UnaryCallable<ListTasksRequest,CloudTasksClient.ListTasksPagedResponse>
listTasksPagedCallable()
Lists the tasks in a queue.Queue
pauseQueue(PauseQueueRequest request)
Pauses the queue.Queue
pauseQueue(QueueName name)
Pauses the queue.Queue
pauseQueue(String name)
Pauses the queue.com.google.api.gax.rpc.UnaryCallable<PauseQueueRequest,Queue>
pauseQueueCallable()
Pauses the queue.Queue
purgeQueue(PurgeQueueRequest request)
Purges a queue by deleting all of its tasks.Queue
purgeQueue(QueueName name)
Purges a queue by deleting all of its tasks.Queue
purgeQueue(String name)
Purges a queue by deleting all of its tasks.com.google.api.gax.rpc.UnaryCallable<PurgeQueueRequest,Queue>
purgeQueueCallable()
Purges a queue by deleting all of its tasks.Task
renewLease(RenewLeaseRequest request)
Renew the current lease of a pull task.Task
renewLease(TaskName name, com.google.protobuf.Timestamp scheduleTime, com.google.protobuf.Duration leaseDuration)
Renew the current lease of a pull task.Task
renewLease(String name, com.google.protobuf.Timestamp scheduleTime, com.google.protobuf.Duration leaseDuration)
Renew the current lease of a pull task.com.google.api.gax.rpc.UnaryCallable<RenewLeaseRequest,Task>
renewLeaseCallable()
Renew the current lease of a pull task.Queue
resumeQueue(QueueName name)
Resume a queue.Queue
resumeQueue(ResumeQueueRequest request)
Resume a queue.Queue
resumeQueue(String name)
Resume a queue.com.google.api.gax.rpc.UnaryCallable<ResumeQueueRequest,Queue>
resumeQueueCallable()
Resume a queue.Task
runTask(RunTaskRequest request)
Forces a task to run now.Task
runTask(TaskName name)
Forces a task to run now.Task
runTask(String name)
Forces a task to run now.com.google.api.gax.rpc.UnaryCallable<RunTaskRequest,Task>
runTaskCallable()
Forces a task to run now.com.google.iam.v1.Policy
setIamPolicy(com.google.api.resourcenames.ResourceName resource, com.google.iam.v1.Policy policy)
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.iam.v1.Policy
setIamPolicy(QueueName queue, com.google.iam.v1.Policy policy)
com.google.iam.v1.Policy
setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.iam.v1.Policy
setIamPolicy(String resource, com.google.iam.v1.Policy policy)
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>
setIamPolicyCallable()
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue].void
shutdown()
void
shutdownNow()
com.google.iam.v1.TestIamPermissionsResponse
testIamPermissions(com.google.api.resourcenames.ResourceName resource, List<String> permissions)
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.iam.v1.TestIamPermissionsResponse
testIamPermissions(QueueName queue, List<String> permissions)
com.google.iam.v1.TestIamPermissionsResponse
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.iam.v1.TestIamPermissionsResponse
testIamPermissions(String resource, List<String> permissions)
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue].com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>
testIamPermissionsCallable()
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue].Queue
updateQueue(Queue queue, com.google.protobuf.FieldMask updateMask)
Updates a queue.Queue
updateQueue(UpdateQueueRequest request)
Updates a queue.com.google.api.gax.rpc.UnaryCallable<UpdateQueueRequest,Queue>
updateQueueCallable()
Updates a queue.void
uploadQueueYaml(UploadQueueYamlRequest request)
Update queue list by uploading a queue.yaml file.com.google.api.gax.rpc.UnaryCallable<UploadQueueYamlRequest,com.google.protobuf.Empty>
uploadQueueYamlCallable()
Update queue list by uploading a queue.yaml file.
-
-
-
Constructor Detail
-
CloudTasksClient
protected CloudTasksClient(CloudTasksSettings settings) throws IOException
Constructs an instance of CloudTasksClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.- Throws:
IOException
-
CloudTasksClient
protected CloudTasksClient(CloudTasksStub stub)
-
-
Method Detail
-
create
public static final CloudTasksClient create() throws IOException
Constructs an instance of CloudTasksClient with default settings.- Throws:
IOException
-
create
public static final CloudTasksClient create(CloudTasksSettings settings) throws IOException
Constructs an instance of CloudTasksClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.- Throws:
IOException
-
create
public static final CloudTasksClient create(CloudTasksStub stub)
Constructs an instance of CloudTasksClient, using the given stub for making calls. This is for advanced usage - prefer using create(CloudTasksSettings).
-
getSettings
public final CloudTasksSettings getSettings()
-
getStub
public CloudTasksStub getStub()
-
listQueues
public final CloudTasksClient.ListQueuesPagedResponse listQueues(LocationName parent)
Lists queues.Queues are returned in lexicographical order.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); for (Queue element : cloudTasksClient.listQueues(parent).iterateAll()) { // doThingsWith(element); } }
- Parameters:
parent
- Required. The location name. For example: `projects/PROJECT_ID/locations/LOCATION_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listQueues
public final CloudTasksClient.ListQueuesPagedResponse listQueues(String parent)
Lists queues.Queues are returned in lexicographical order.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); for (Queue element : cloudTasksClient.listQueues(parent).iterateAll()) { // doThingsWith(element); } }
- Parameters:
parent
- Required. The location name. For example: `projects/PROJECT_ID/locations/LOCATION_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listQueues
public final CloudTasksClient.ListQueuesPagedResponse listQueues(ListQueuesRequest request)
Lists queues.Queues are returned in lexicographical order.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListQueuesRequest request = ListQueuesRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setFilter("filter-1274492040") .setPageSize(883849137) .setPageToken("pageToken873572522") .setReadMask(FieldMask.newBuilder().build()) .build(); for (Queue element : cloudTasksClient.listQueues(request).iterateAll()) { // doThingsWith(element); } }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listQueuesPagedCallable
public final com.google.api.gax.rpc.UnaryCallable<ListQueuesRequest,CloudTasksClient.ListQueuesPagedResponse> listQueuesPagedCallable()
Lists queues.Queues are returned in lexicographical order.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListQueuesRequest request = ListQueuesRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setFilter("filter-1274492040") .setPageSize(883849137) .setPageToken("pageToken873572522") .setReadMask(FieldMask.newBuilder().build()) .build(); ApiFuture<Queue> future = cloudTasksClient.listQueuesPagedCallable().futureCall(request); // Do something. for (Queue element : future.get().iterateAll()) { // doThingsWith(element); } }
-
listQueuesCallable
public final com.google.api.gax.rpc.UnaryCallable<ListQueuesRequest,ListQueuesResponse> listQueuesCallable()
Lists queues.Queues are returned in lexicographical order.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListQueuesRequest request = ListQueuesRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setFilter("filter-1274492040") .setPageSize(883849137) .setPageToken("pageToken873572522") .setReadMask(FieldMask.newBuilder().build()) .build(); while (true) { ListQueuesResponse response = cloudTasksClient.listQueuesCallable().call(request); for (Queue element : response.getQueuesList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } }
-
getQueue
public final Queue getQueue(QueueName name)
Gets a queue.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Queue response = cloudTasksClient.getQueue(name); }
- Parameters:
name
- Required. The resource name of the queue. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getQueue
public final Queue getQueue(String name)
Gets a queue.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); Queue response = cloudTasksClient.getQueue(name); }
- Parameters:
name
- Required. The resource name of the queue. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getQueue
public final Queue getQueue(GetQueueRequest request)
Gets a queue.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetQueueRequest request = GetQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setReadMask(FieldMask.newBuilder().build()) .build(); Queue response = cloudTasksClient.getQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<GetQueueRequest,Queue> getQueueCallable()
Gets a queue.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetQueueRequest request = GetQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setReadMask(FieldMask.newBuilder().build()) .build(); ApiFuture<Queue> future = cloudTasksClient.getQueueCallable().futureCall(request); // Do something. Queue response = future.get(); }
-
createQueue
public final Queue createQueue(LocationName parent, Queue queue)
Creates a queue.Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); Queue queue = Queue.newBuilder().build(); Queue response = cloudTasksClient.createQueue(parent, queue); }
- Parameters:
parent
- Required. The location name in which the queue will be created. For example: `projects/PROJECT_ID/locations/LOCATION_ID`The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations].
queue
- Required. The queue to create.[Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing queue.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
createQueue
public final Queue createQueue(String parent, Queue queue)
Creates a queue.Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); Queue queue = Queue.newBuilder().build(); Queue response = cloudTasksClient.createQueue(parent, queue); }
- Parameters:
parent
- Required. The location name in which the queue will be created. For example: `projects/PROJECT_ID/locations/LOCATION_ID`The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations].
queue
- Required. The queue to create.[Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing queue.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
createQueue
public final Queue createQueue(CreateQueueRequest request)
Creates a queue.Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { CreateQueueRequest request = CreateQueueRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setQueue(Queue.newBuilder().build()) .build(); Queue response = cloudTasksClient.createQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
createQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<CreateQueueRequest,Queue> createQueueCallable()
Creates a queue.Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { CreateQueueRequest request = CreateQueueRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setQueue(Queue.newBuilder().build()) .build(); ApiFuture<Queue> future = cloudTasksClient.createQueueCallable().futureCall(request); // Do something. Queue response = future.get(); }
-
updateQueue
public final Queue updateQueue(Queue queue, com.google.protobuf.FieldMask updateMask)
Updates a queue.This method creates the queue if it does not exist and updates the queue if it does exist.
Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { Queue queue = Queue.newBuilder().build(); FieldMask updateMask = FieldMask.newBuilder().build(); Queue response = cloudTasksClient.updateQueue(queue, updateMask); }
- Parameters:
queue
- Required. The queue to create or update.The queue's [name][google.cloud.tasks.v2beta2.Queue.name] must be specified.
Output only fields cannot be modified using UpdateQueue. Any value specified for an output only field will be ignored. The queue's [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed.
updateMask
- A mask used to specify which fields of the queue are being updated.If empty, then all fields will be updated.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
updateQueue
public final Queue updateQueue(UpdateQueueRequest request)
Updates a queue.This method creates the queue if it does not exist and updates the queue if it does exist.
Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { UpdateQueueRequest request = UpdateQueueRequest.newBuilder() .setQueue(Queue.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); Queue response = cloudTasksClient.updateQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
updateQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<UpdateQueueRequest,Queue> updateQueueCallable()
Updates a queue.This method creates the queue if it does not exist and updates the queue if it does exist.
Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { UpdateQueueRequest request = UpdateQueueRequest.newBuilder() .setQueue(Queue.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); ApiFuture<Queue> future = cloudTasksClient.updateQueueCallable().futureCall(request); // Do something. Queue response = future.get(); }
-
deleteQueue
public final void deleteQueue(QueueName name)
Deletes a queue.This command will delete the queue even if it has tasks in it.
Note: If you delete a queue, a queue with the same name can't be created for 7 days.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); cloudTasksClient.deleteQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
deleteQueue
public final void deleteQueue(String name)
Deletes a queue.This command will delete the queue even if it has tasks in it.
Note: If you delete a queue, a queue with the same name can't be created for 7 days.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); cloudTasksClient.deleteQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
deleteQueue
public final void deleteQueue(DeleteQueueRequest request)
Deletes a queue.This command will delete the queue even if it has tasks in it.
Note: If you delete a queue, a queue with the same name can't be created for 7 days.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { DeleteQueueRequest request = DeleteQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); cloudTasksClient.deleteQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
deleteQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<DeleteQueueRequest,com.google.protobuf.Empty> deleteQueueCallable()
Deletes a queue.This command will delete the queue even if it has tasks in it.
Note: If you delete a queue, a queue with the same name can't be created for 7 days.
WARNING: Using this method may have unintended side effects if you are using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { DeleteQueueRequest request = DeleteQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); ApiFuture<Empty> future = cloudTasksClient.deleteQueueCallable().futureCall(request); // Do something. future.get(); }
-
purgeQueue
public final Queue purgeQueue(QueueName name)
Purges a queue by deleting all of its tasks.All tasks created before this method is called are permanently deleted.
Purge operations can take up to one minute to take effect. Tasks might be dispatched before the purge takes effect. A purge is irreversible.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Queue response = cloudTasksClient.purgeQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
purgeQueue
public final Queue purgeQueue(String name)
Purges a queue by deleting all of its tasks.All tasks created before this method is called are permanently deleted.
Purge operations can take up to one minute to take effect. Tasks might be dispatched before the purge takes effect. A purge is irreversible.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); Queue response = cloudTasksClient.purgeQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
purgeQueue
public final Queue purgeQueue(PurgeQueueRequest request)
Purges a queue by deleting all of its tasks.All tasks created before this method is called are permanently deleted.
Purge operations can take up to one minute to take effect. Tasks might be dispatched before the purge takes effect. A purge is irreversible.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { PurgeQueueRequest request = PurgeQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); Queue response = cloudTasksClient.purgeQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
purgeQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<PurgeQueueRequest,Queue> purgeQueueCallable()
Purges a queue by deleting all of its tasks.All tasks created before this method is called are permanently deleted.
Purge operations can take up to one minute to take effect. Tasks might be dispatched before the purge takes effect. A purge is irreversible.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { PurgeQueueRequest request = PurgeQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); ApiFuture<Queue> future = cloudTasksClient.purgeQueueCallable().futureCall(request); // Do something. Queue response = future.get(); }
-
pauseQueue
public final Queue pauseQueue(QueueName name)
Pauses the queue.If a queue is paused then the system will stop dispatching tasks until the queue is resumed via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added when the queue is paused. A queue is paused if its [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Queue response = cloudTasksClient.pauseQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
pauseQueue
public final Queue pauseQueue(String name)
Pauses the queue.If a queue is paused then the system will stop dispatching tasks until the queue is resumed via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added when the queue is paused. A queue is paused if its [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); Queue response = cloudTasksClient.pauseQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
pauseQueue
public final Queue pauseQueue(PauseQueueRequest request)
Pauses the queue.If a queue is paused then the system will stop dispatching tasks until the queue is resumed via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added when the queue is paused. A queue is paused if its [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { PauseQueueRequest request = PauseQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); Queue response = cloudTasksClient.pauseQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
pauseQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<PauseQueueRequest,Queue> pauseQueueCallable()
Pauses the queue.If a queue is paused then the system will stop dispatching tasks until the queue is resumed via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added when the queue is paused. A queue is paused if its [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { PauseQueueRequest request = PauseQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); ApiFuture<Queue> future = cloudTasksClient.pauseQueueCallable().futureCall(request); // Do something. Queue response = future.get(); }
-
resumeQueue
public final Queue resumeQueue(QueueName name)
Resume a queue.This method resumes a queue after it has been [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING].
WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Queue response = cloudTasksClient.resumeQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
resumeQueue
public final Queue resumeQueue(String name)
Resume a queue.This method resumes a queue after it has been [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING].
WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); Queue response = cloudTasksClient.resumeQueue(name); }
- Parameters:
name
- Required. The queue name. For example: `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
resumeQueue
public final Queue resumeQueue(ResumeQueueRequest request)
Resume a queue.This method resumes a queue after it has been [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING].
WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ResumeQueueRequest request = ResumeQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); Queue response = cloudTasksClient.resumeQueue(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
resumeQueueCallable
public final com.google.api.gax.rpc.UnaryCallable<ResumeQueueRequest,Queue> resumeQueueCallable()
Resume a queue.This method resumes a queue after it has been [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING].
WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ResumeQueueRequest request = ResumeQueueRequest.newBuilder() .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .build(); ApiFuture<Queue> future = cloudTasksClient.resumeQueueCallable().futureCall(request); // Do something. Queue response = future.get(); }
-
uploadQueueYaml
public final void uploadQueueYaml(UploadQueueYamlRequest request)
Update queue list by uploading a queue.yaml file.The queue.yaml file is supplied in the request body as a YAML encoded string. This method was added to support gcloud clients versions before 322.0.0. New clients should use CreateQueue instead of this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { UploadQueueYamlRequest request = UploadQueueYamlRequest.newBuilder() .setAppId("appId93028124") .setHttpBody(HttpBody.newBuilder().build()) .build(); cloudTasksClient.uploadQueueYaml(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
uploadQueueYamlCallable
public final com.google.api.gax.rpc.UnaryCallable<UploadQueueYamlRequest,com.google.protobuf.Empty> uploadQueueYamlCallable()
Update queue list by uploading a queue.yaml file.The queue.yaml file is supplied in the request body as a YAML encoded string. This method was added to support gcloud clients versions before 322.0.0. New clients should use CreateQueue instead of this method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { UploadQueueYamlRequest request = UploadQueueYamlRequest.newBuilder() .setAppId("appId93028124") .setHttpBody(HttpBody.newBuilder().build()) .build(); ApiFuture<Empty> future = cloudTasksClient.uploadQueueYamlCallable().futureCall(request); // Do something. future.get(); }
-
getIamPolicy
public final com.google.iam.v1.Policy getIamPolicy(com.google.api.resourcenames.ResourceName resource)
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an empty policy if the resource exists and does not have a policy set.Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.getIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Policy response = cloudTasksClient.getIamPolicy(resource); }
- Parameters:
resource
- REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getIamPolicy
public final com.google.iam.v1.Policy getIamPolicy(String resource)
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an empty policy if the resource exists and does not have a policy set.Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.getIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String resource = LocationName.of("[PROJECT]", "[LOCATION]").toString(); Policy response = cloudTasksClient.getIamPolicy(resource); }
- Parameters:
resource
- REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getIamPolicy
public final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an empty policy if the resource exists and does not have a policy set.Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.getIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setOptions(GetPolicyOptions.newBuilder().build()) .build(); Policy response = cloudTasksClient.getIamPolicy(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getIamPolicy
public final com.google.iam.v1.Policy getIamPolicy(QueueName queueName)
-
getIamPolicyCallable
public final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an empty policy if the resource exists and does not have a policy set.Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.getIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setOptions(GetPolicyOptions.newBuilder().build()) .build(); ApiFuture<Policy> future = cloudTasksClient.getIamPolicyCallable().futureCall(request); // Do something. Policy response = future.get(); }
-
setIamPolicy
public final com.google.iam.v1.Policy setIamPolicy(com.google.api.resourcenames.ResourceName resource, com.google.iam.v1.Policy policy)
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing policy.Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level permissions are required to use the Cloud Console.
Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.setIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Policy policy = Policy.newBuilder().build(); Policy response = cloudTasksClient.setIamPolicy(resource, policy); }
- Parameters:
resource
- REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.policy
- REQUIRED: The complete policy to be applied to the `resource`. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
setIamPolicy
public final com.google.iam.v1.Policy setIamPolicy(String resource, com.google.iam.v1.Policy policy)
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing policy.Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level permissions are required to use the Cloud Console.
Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.setIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String resource = LocationName.of("[PROJECT]", "[LOCATION]").toString(); Policy policy = Policy.newBuilder().build(); Policy response = cloudTasksClient.setIamPolicy(resource, policy); }
- Parameters:
resource
- REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.policy
- REQUIRED: The complete policy to be applied to the `resource`. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
setIamPolicy
public final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing policy.Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level permissions are required to use the Cloud Console.
Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.setIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setPolicy(Policy.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); Policy response = cloudTasksClient.setIamPolicy(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
setIamPolicy
public final com.google.iam.v1.Policy setIamPolicy(QueueName queue, com.google.iam.v1.Policy policy)
-
setIamPolicyCallable
public final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing policy.Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level permissions are required to use the Cloud Console.
Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission on the specified resource parent:
- `cloudtasks.queues.setIamPolicy`
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setPolicy(Policy.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); ApiFuture<Policy> future = cloudTasksClient.setIamPolicyCallable().futureCall(request); // Do something. Policy response = future.get(); }
-
testIamPermissions
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.api.resourcenames.ResourceName resource, List<String> permissions)
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the resource does not exist, this will return an empty set of permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); List<String> permissions = new ArrayList<>(); TestIamPermissionsResponse response = cloudTasksClient.testIamPermissions(resource, permissions); }
- Parameters:
resource
- REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.permissions
- The set of permissions to check for the `resource`. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
testIamPermissions
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the resource does not exist, this will return an empty set of permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String resource = LocationName.of("[PROJECT]", "[LOCATION]").toString(); List<String> permissions = new ArrayList<>(); TestIamPermissionsResponse response = cloudTasksClient.testIamPermissions(resource, permissions); }
- Parameters:
resource
- REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.permissions
- The set of permissions to check for the `resource`. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
testIamPermissions
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the resource does not exist, this will return an empty set of permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .addAllPermissions(new ArrayList<String>()) .build(); TestIamPermissionsResponse response = cloudTasksClient.testIamPermissions(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
testIamPermissions
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(QueueName queue, List<String> permissions)
-
testIamPermissionsCallable
public final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the resource does not exist, this will return an empty set of permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .addAllPermissions(new ArrayList<String>()) .build(); ApiFuture<TestIamPermissionsResponse> future = cloudTasksClient.testIamPermissionsCallable().futureCall(request); // Do something. TestIamPermissionsResponse response = future.get(); }
-
listTasks
public final CloudTasksClient.ListTasksPagedResponse listTasks(QueueName parent)
Lists the tasks in a queue.By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved due to performance considerations; [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset of information which is returned.
The tasks may be returned in any order. The ordering may change at any time.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); for (Task element : cloudTasksClient.listTasks(parent).iterateAll()) { // doThingsWith(element); } }
- Parameters:
parent
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listTasks
public final CloudTasksClient.ListTasksPagedResponse listTasks(String parent)
Lists the tasks in a queue.By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved due to performance considerations; [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset of information which is returned.
The tasks may be returned in any order. The ordering may change at any time.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); for (Task element : cloudTasksClient.listTasks(parent).iterateAll()) { // doThingsWith(element); } }
- Parameters:
parent
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listTasks
public final CloudTasksClient.ListTasksPagedResponse listTasks(ListTasksRequest request)
Lists the tasks in a queue.By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved due to performance considerations; [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset of information which is returned.
The tasks may be returned in any order. The ordering may change at any time.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListTasksRequest request = ListTasksRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); for (Task element : cloudTasksClient.listTasks(request).iterateAll()) { // doThingsWith(element); } }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listTasksPagedCallable
public final com.google.api.gax.rpc.UnaryCallable<ListTasksRequest,CloudTasksClient.ListTasksPagedResponse> listTasksPagedCallable()
Lists the tasks in a queue.By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved due to performance considerations; [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset of information which is returned.
The tasks may be returned in any order. The ordering may change at any time.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListTasksRequest request = ListTasksRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); ApiFuture<Task> future = cloudTasksClient.listTasksPagedCallable().futureCall(request); // Do something. for (Task element : future.get().iterateAll()) { // doThingsWith(element); } }
-
listTasksCallable
public final com.google.api.gax.rpc.UnaryCallable<ListTasksRequest,ListTasksResponse> listTasksCallable()
Lists the tasks in a queue.By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved due to performance considerations; [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset of information which is returned.
The tasks may be returned in any order. The ordering may change at any time.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListTasksRequest request = ListTasksRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); while (true) { ListTasksResponse response = cloudTasksClient.listTasksCallable().call(request); for (Task element : response.getTasksList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } }
-
getTask
public final Task getTask(TaskName name)
Gets a task.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); Task response = cloudTasksClient.getTask(name); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getTask
public final Task getTask(String name)
Gets a task.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); Task response = cloudTasksClient.getTask(name); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getTask
public final Task getTask(GetTaskRequest request)
Gets a task.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetTaskRequest request = GetTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .build(); Task response = cloudTasksClient.getTask(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getTaskCallable
public final com.google.api.gax.rpc.UnaryCallable<GetTaskRequest,Task> getTaskCallable()
Gets a task.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetTaskRequest request = GetTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .build(); ApiFuture<Task> future = cloudTasksClient.getTaskCallable().futureCall(request); // Do something. Task response = future.get(); }
-
createTask
public final Task createTask(QueueName parent, Task task)
Creates a task and adds it to a queue.Tasks cannot be updated after creation; there is no UpdateTask command.
- For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is 100KB.
- For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Task task = Task.newBuilder().build(); Task response = cloudTasksClient.createTask(parent, task); }
- Parameters:
parent
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`The queue must already exist.
task
- Required. The task to add.Task names have the following format: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. The user can optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a name is not specified then the system will generate a random unique task id, which will be set in the task returned in the [response][google.cloud.tasks.v2beta2.Task.name].
If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in the past then Cloud Tasks will set it to the current time.
Task De-duplication:
Explicitly specifying a task ID enables task de-duplication. If a task's ID is identical to that of an existing task or a task that was deleted or completed recently then the call will fail with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. If the task's queue was created using Cloud Tasks, then another task with the same name can't be created for ~1 hour after the original task was deleted or completed. If the task's queue was created using queue.yaml or queue.xml, then another task with the same name can't be created for ~9 days after the original task was deleted or completed.
Because there is an extra lookup cost to identify duplicate task names, these [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly increased latency. Using hashed strings for the task id or for the prefix of the task id is recommended. Choosing task ids that are sequential or have sequential prefixes, for example using a timestamp, causes an increase in latency and error rates in all task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
createTask
public final Task createTask(String parent, Task task)
Creates a task and adds it to a queue.Tasks cannot be updated after creation; there is no UpdateTask command.
- For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is 100KB.
- For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); Task task = Task.newBuilder().build(); Task response = cloudTasksClient.createTask(parent, task); }
- Parameters:
parent
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`The queue must already exist.
task
- Required. The task to add.Task names have the following format: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. The user can optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a name is not specified then the system will generate a random unique task id, which will be set in the task returned in the [response][google.cloud.tasks.v2beta2.Task.name].
If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in the past then Cloud Tasks will set it to the current time.
Task De-duplication:
Explicitly specifying a task ID enables task de-duplication. If a task's ID is identical to that of an existing task or a task that was deleted or completed recently then the call will fail with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. If the task's queue was created using Cloud Tasks, then another task with the same name can't be created for ~1 hour after the original task was deleted or completed. If the task's queue was created using queue.yaml or queue.xml, then another task with the same name can't be created for ~9 days after the original task was deleted or completed.
Because there is an extra lookup cost to identify duplicate task names, these [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly increased latency. Using hashed strings for the task id or for the prefix of the task id is recommended. Choosing task ids that are sequential or have sequential prefixes, for example using a timestamp, causes an increase in latency and error rates in all task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
createTask
public final Task createTask(CreateTaskRequest request)
Creates a task and adds it to a queue.Tasks cannot be updated after creation; there is no UpdateTask command.
- For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is 100KB.
- For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { CreateTaskRequest request = CreateTaskRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setTask(Task.newBuilder().build()) .build(); Task response = cloudTasksClient.createTask(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
createTaskCallable
public final com.google.api.gax.rpc.UnaryCallable<CreateTaskRequest,Task> createTaskCallable()
Creates a task and adds it to a queue.Tasks cannot be updated after creation; there is no UpdateTask command.
- For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is 100KB.
- For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { CreateTaskRequest request = CreateTaskRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setTask(Task.newBuilder().build()) .build(); ApiFuture<Task> future = cloudTasksClient.createTaskCallable().futureCall(request); // Do something. Task response = future.get(); }
-
deleteTask
public final void deleteTask(TaskName name)
Deletes a task.A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has completed successfully or permanently failed.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); cloudTasksClient.deleteTask(name); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
deleteTask
public final void deleteTask(String name)
Deletes a task.A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has completed successfully or permanently failed.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); cloudTasksClient.deleteTask(name); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
deleteTask
public final void deleteTask(DeleteTaskRequest request)
Deletes a task.A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has completed successfully or permanently failed.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { DeleteTaskRequest request = DeleteTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .build(); cloudTasksClient.deleteTask(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
deleteTaskCallable
public final com.google.api.gax.rpc.UnaryCallable<DeleteTaskRequest,com.google.protobuf.Empty> deleteTaskCallable()
Deletes a task.A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has completed successfully or permanently failed.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { DeleteTaskRequest request = DeleteTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .build(); ApiFuture<Empty> future = cloudTasksClient.deleteTaskCallable().futureCall(request); // Do something. future.get(); }
-
leaseTasks
public final LeaseTasksResponse leaseTasks(QueueName parent, com.google.protobuf.Duration leaseDuration)
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].This method is invoked by the worker to obtain a lease. The worker must acknowledge the task via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have performed the work associated with the task.
The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that the worker needs to perform the work associated with the task. To return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to [FULL][google.cloud.tasks.v2beta2.Task.View.FULL].
A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is also returned when [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] is exceeded.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Duration leaseDuration = Duration.newBuilder().build(); LeaseTasksResponse response = cloudTasksClient.leaseTasks(parent, leaseDuration); }
- Parameters:
parent
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`leaseDuration
- Required. The duration of the lease.Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current time plus the `lease_duration`. The task is leased until its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
After the worker has successfully finished the work associated with the task, the worker must call via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] before the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Otherwise the task will be returned to a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call so that another worker can retry it.
The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest second.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
leaseTasks
public final LeaseTasksResponse leaseTasks(String parent, com.google.protobuf.Duration leaseDuration)
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].This method is invoked by the worker to obtain a lease. The worker must acknowledge the task via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have performed the work associated with the task.
The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that the worker needs to perform the work associated with the task. To return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to [FULL][google.cloud.tasks.v2beta2.Task.View.FULL].
A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is also returned when [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] is exceeded.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); Duration leaseDuration = Duration.newBuilder().build(); LeaseTasksResponse response = cloudTasksClient.leaseTasks(parent, leaseDuration); }
- Parameters:
parent
- Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`leaseDuration
- Required. The duration of the lease.Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current time plus the `lease_duration`. The task is leased until its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
After the worker has successfully finished the work associated with the task, the worker must call via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] before the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Otherwise the task will be returned to a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call so that another worker can retry it.
The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest second.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
leaseTasks
public final LeaseTasksResponse leaseTasks(LeaseTasksRequest request)
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].This method is invoked by the worker to obtain a lease. The worker must acknowledge the task via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have performed the work associated with the task.
The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that the worker needs to perform the work associated with the task. To return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to [FULL][google.cloud.tasks.v2beta2.Task.View.FULL].
A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is also returned when [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] is exceeded.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { LeaseTasksRequest request = LeaseTasksRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setMaxTasks(-233969421) .setLeaseDuration(Duration.newBuilder().build()) .setFilter("filter-1274492040") .build(); LeaseTasksResponse response = cloudTasksClient.leaseTasks(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
leaseTasksCallable
public final com.google.api.gax.rpc.UnaryCallable<LeaseTasksRequest,LeaseTasksResponse> leaseTasksCallable()
Leases tasks from a pull queue for [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].This method is invoked by the worker to obtain a lease. The worker must acknowledge the task via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have performed the work associated with the task.
The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that the worker needs to perform the work associated with the task. To return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to [FULL][google.cloud.tasks.v2beta2.Task.View.FULL].
A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is also returned when [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] is exceeded.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { LeaseTasksRequest request = LeaseTasksRequest.newBuilder() .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setMaxTasks(-233969421) .setLeaseDuration(Duration.newBuilder().build()) .setFilter("filter-1274492040") .build(); ApiFuture<LeaseTasksResponse> future = cloudTasksClient.leaseTasksCallable().futureCall(request); // Do something. LeaseTasksResponse response = future.get(); }
-
acknowledgeTask
public final void acknowledgeTask(TaskName name, com.google.protobuf.Timestamp scheduleTime)
Acknowledges a pull task.The worker, that is, the entity that [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to indicate that the work associated with the task has finished.
The worker must acknowledge a task within the [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will expire and the task will become available to be leased again. After the task is acknowledged, it will not be returned by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); Timestamp scheduleTime = Timestamp.newBuilder().build(); cloudTasksClient.acknowledgeTask(name, scheduleTime); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`scheduleTime
- Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
acknowledgeTask
public final void acknowledgeTask(String name, com.google.protobuf.Timestamp scheduleTime)
Acknowledges a pull task.The worker, that is, the entity that [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to indicate that the work associated with the task has finished.
The worker must acknowledge a task within the [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will expire and the task will become available to be leased again. After the task is acknowledged, it will not be returned by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); Timestamp scheduleTime = Timestamp.newBuilder().build(); cloudTasksClient.acknowledgeTask(name, scheduleTime); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`scheduleTime
- Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
acknowledgeTask
public final void acknowledgeTask(AcknowledgeTaskRequest request)
Acknowledges a pull task.The worker, that is, the entity that [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to indicate that the work associated with the task has finished.
The worker must acknowledge a task within the [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will expire and the task will become available to be leased again. After the task is acknowledged, it will not be returned by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { AcknowledgeTaskRequest request = AcknowledgeTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .setScheduleTime(Timestamp.newBuilder().build()) .build(); cloudTasksClient.acknowledgeTask(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
acknowledgeTaskCallable
public final com.google.api.gax.rpc.UnaryCallable<AcknowledgeTaskRequest,com.google.protobuf.Empty> acknowledgeTaskCallable()
Acknowledges a pull task.The worker, that is, the entity that [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to indicate that the work associated with the task has finished.
The worker must acknowledge a task within the [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will expire and the task will become available to be leased again. After the task is acknowledged, it will not be returned by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { AcknowledgeTaskRequest request = AcknowledgeTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .setScheduleTime(Timestamp.newBuilder().build()) .build(); ApiFuture<Empty> future = cloudTasksClient.acknowledgeTaskCallable().futureCall(request); // Do something. future.get(); }
-
renewLease
public final Task renewLease(TaskName name, com.google.protobuf.Timestamp scheduleTime, com.google.protobuf.Duration leaseDuration)
Renew the current lease of a pull task.The worker can use this method to extend the lease by a new duration, starting from now. The new task lease will be returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); Timestamp scheduleTime = Timestamp.newBuilder().build(); Duration leaseDuration = Duration.newBuilder().build(); Task response = cloudTasksClient.renewLease(name, scheduleTime, leaseDuration); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`scheduleTime
- Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease.leaseDuration
- Required. The desired new lease duration, starting from now.The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest second.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
renewLease
public final Task renewLease(String name, com.google.protobuf.Timestamp scheduleTime, com.google.protobuf.Duration leaseDuration)
Renew the current lease of a pull task.The worker can use this method to extend the lease by a new duration, starting from now. The new task lease will be returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); Timestamp scheduleTime = Timestamp.newBuilder().build(); Duration leaseDuration = Duration.newBuilder().build(); Task response = cloudTasksClient.renewLease(name, scheduleTime, leaseDuration); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`scheduleTime
- Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease.leaseDuration
- Required. The desired new lease duration, starting from now.The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest second.
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
renewLease
public final Task renewLease(RenewLeaseRequest request)
Renew the current lease of a pull task.The worker can use this method to extend the lease by a new duration, starting from now. The new task lease will be returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { RenewLeaseRequest request = RenewLeaseRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .setScheduleTime(Timestamp.newBuilder().build()) .setLeaseDuration(Duration.newBuilder().build()) .build(); Task response = cloudTasksClient.renewLease(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
renewLeaseCallable
public final com.google.api.gax.rpc.UnaryCallable<RenewLeaseRequest,Task> renewLeaseCallable()
Renew the current lease of a pull task.The worker can use this method to extend the lease by a new duration, starting from now. The new task lease will be returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { RenewLeaseRequest request = RenewLeaseRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .setScheduleTime(Timestamp.newBuilder().build()) .setLeaseDuration(Duration.newBuilder().build()) .build(); ApiFuture<Task> future = cloudTasksClient.renewLeaseCallable().futureCall(request); // Do something. Task response = future.get(); }
-
cancelLease
public final Task cancelLease(TaskName name, com.google.protobuf.Timestamp scheduleTime)
Cancel a pull task's lease.The worker can use this method to cancel a task's lease by setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task available to be leased to the next caller of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); Timestamp scheduleTime = Timestamp.newBuilder().build(); Task response = cloudTasksClient.cancelLease(name, scheduleTime); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`scheduleTime
- Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
cancelLease
public final Task cancelLease(String name, com.google.protobuf.Timestamp scheduleTime)
Cancel a pull task's lease.The worker can use this method to cancel a task's lease by setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task available to be leased to the next caller of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); Timestamp scheduleTime = Timestamp.newBuilder().build(); Task response = cloudTasksClient.cancelLease(name, scheduleTime); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`scheduleTime
- Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
cancelLease
public final Task cancelLease(CancelLeaseRequest request)
Cancel a pull task's lease.The worker can use this method to cancel a task's lease by setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task available to be leased to the next caller of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { CancelLeaseRequest request = CancelLeaseRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .setScheduleTime(Timestamp.newBuilder().build()) .build(); Task response = cloudTasksClient.cancelLease(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
cancelLeaseCallable
public final com.google.api.gax.rpc.UnaryCallable<CancelLeaseRequest,Task> cancelLeaseCallable()
Cancel a pull task's lease.The worker can use this method to cancel a task's lease by setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task available to be leased to the next caller of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { CancelLeaseRequest request = CancelLeaseRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .setScheduleTime(Timestamp.newBuilder().build()) .build(); ApiFuture<Task> future = cloudTasksClient.cancelLeaseCallable().futureCall(request); // Do something. Task response = future.get(); }
-
runTask
public final Task runTask(TaskName name)
Forces a task to run now.When this method is called, Cloud Tasks will dispatch the task, even if the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
This command is meant to be used for manual debugging. For example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task after a fix has been made or to manually force a task to be dispatched now.
The dispatched task is returned. That is, the task that is returned contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the task is received by its target.
If Cloud Tasks receives a successful response from the task's target, then the task will be deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig].
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded or permanently failed.
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull task][google.cloud.tasks.v2beta2.PullMessage].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); Task response = cloudTasksClient.runTask(name); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
runTask
public final Task runTask(String name)
Forces a task to run now.When this method is called, Cloud Tasks will dispatch the task, even if the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
This command is meant to be used for manual debugging. For example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task after a fix has been made or to manually force a task to be dispatched now.
The dispatched task is returned. That is, the task that is returned contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the task is received by its target.
If Cloud Tasks receives a successful response from the task's target, then the task will be deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig].
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded or permanently failed.
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull task][google.cloud.tasks.v2beta2.PullMessage].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); Task response = cloudTasksClient.runTask(name); }
- Parameters:
name
- Required. The task name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
runTask
public final Task runTask(RunTaskRequest request)
Forces a task to run now.When this method is called, Cloud Tasks will dispatch the task, even if the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
This command is meant to be used for manual debugging. For example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task after a fix has been made or to manually force a task to be dispatched now.
The dispatched task is returned. That is, the task that is returned contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the task is received by its target.
If Cloud Tasks receives a successful response from the task's target, then the task will be deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig].
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded or permanently failed.
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull task][google.cloud.tasks.v2beta2.PullMessage].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { RunTaskRequest request = RunTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .build(); Task response = cloudTasksClient.runTask(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
runTaskCallable
public final com.google.api.gax.rpc.UnaryCallable<RunTaskRequest,Task> runTaskCallable()
Forces a task to run now.When this method is called, Cloud Tasks will dispatch the task, even if the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
This command is meant to be used for manual debugging. For example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task after a fix has been made or to manually force a task to be dispatched now.
The dispatched task is returned. That is, the task that is returned contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the task is received by its target.
If Cloud Tasks receives a successful response from the task's target, then the task will be deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig].
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded or permanently failed.
[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull task][google.cloud.tasks.v2beta2.PullMessage].
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { RunTaskRequest request = RunTaskRequest.newBuilder() .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) .build(); ApiFuture<Task> future = cloudTasksClient.runTaskCallable().futureCall(request); // Do something. Task response = future.get(); }
-
bufferTask
public final BufferTaskResponse bufferTask(QueueName queue, String taskId, com.google.api.HttpBody body)
Creates and buffers a new task without the need to explicitly define a Task message. The queue must have [HTTP target][google.cloud.tasks.v2beta2.HttpTarget]. To create the task with a custom ID, use the following format and set TASK_ID to your desired ID: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID:buffer To create the task with an automatically generated ID, use the following format: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks:buffer. Note: This feature is in its experimental stage. You must request access to the API through the [Cloud Tasks BufferTask Experiment Signup form](https://forms.gle/X8Zr5hiXH5tTGFqh8).Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName queue = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); String taskId = "taskId-880873088"; HttpBody body = HttpBody.newBuilder().build(); BufferTaskResponse response = cloudTasksClient.bufferTask(queue, taskId, body); }
- Parameters:
queue
- Required. The parent queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`The queue must already exist.
taskId
- Optional. Task ID for the task being created. If not provided, a random task ID is assigned to the task.body
- Optional. Body of the HTTP request.The body can take any generic value. The value is written to the [HttpRequest][payload] of the [Task].
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
bufferTask
public final BufferTaskResponse bufferTask(String queue, String taskId, com.google.api.HttpBody body)
Creates and buffers a new task without the need to explicitly define a Task message. The queue must have [HTTP target][google.cloud.tasks.v2beta2.HttpTarget]. To create the task with a custom ID, use the following format and set TASK_ID to your desired ID: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID:buffer To create the task with an automatically generated ID, use the following format: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks:buffer. Note: This feature is in its experimental stage. You must request access to the API through the [Cloud Tasks BufferTask Experiment Signup form](https://forms.gle/X8Zr5hiXH5tTGFqh8).Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { String queue = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); String taskId = "taskId-880873088"; HttpBody body = HttpBody.newBuilder().build(); BufferTaskResponse response = cloudTasksClient.bufferTask(queue, taskId, body); }
- Parameters:
queue
- Required. The parent queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`The queue must already exist.
taskId
- Optional. Task ID for the task being created. If not provided, a random task ID is assigned to the task.body
- Optional. Body of the HTTP request.The body can take any generic value. The value is written to the [HttpRequest][payload] of the [Task].
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
bufferTask
public final BufferTaskResponse bufferTask(BufferTaskRequest request)
Creates and buffers a new task without the need to explicitly define a Task message. The queue must have [HTTP target][google.cloud.tasks.v2beta2.HttpTarget]. To create the task with a custom ID, use the following format and set TASK_ID to your desired ID: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID:buffer To create the task with an automatically generated ID, use the following format: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks:buffer. Note: This feature is in its experimental stage. You must request access to the API through the [Cloud Tasks BufferTask Experiment Signup form](https://forms.gle/X8Zr5hiXH5tTGFqh8).Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { BufferTaskRequest request = BufferTaskRequest.newBuilder() .setQueue(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setTaskId("taskId-880873088") .setBody(HttpBody.newBuilder().build()) .build(); BufferTaskResponse response = cloudTasksClient.bufferTask(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
bufferTaskCallable
public final com.google.api.gax.rpc.UnaryCallable<BufferTaskRequest,BufferTaskResponse> bufferTaskCallable()
Creates and buffers a new task without the need to explicitly define a Task message. The queue must have [HTTP target][google.cloud.tasks.v2beta2.HttpTarget]. To create the task with a custom ID, use the following format and set TASK_ID to your desired ID: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID:buffer To create the task with an automatically generated ID, use the following format: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks:buffer. Note: This feature is in its experimental stage. You must request access to the API through the [Cloud Tasks BufferTask Experiment Signup form](https://forms.gle/X8Zr5hiXH5tTGFqh8).Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { BufferTaskRequest request = BufferTaskRequest.newBuilder() .setQueue(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) .setTaskId("taskId-880873088") .setBody(HttpBody.newBuilder().build()) .build(); ApiFuture<BufferTaskResponse> future = cloudTasksClient.bufferTaskCallable().futureCall(request); // Do something. BufferTaskResponse response = future.get(); }
-
listLocations
public final CloudTasksClient.ListLocationsPagedResponse listLocations(com.google.cloud.location.ListLocationsRequest request)
Lists information about the supported locations for this service.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListLocationsRequest request = ListLocationsRequest.newBuilder() .setName("name3373707") .setFilter("filter-1274492040") .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); for (Location element : cloudTasksClient.listLocations(request).iterateAll()) { // doThingsWith(element); } }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listLocationsPagedCallable
public final com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,CloudTasksClient.ListLocationsPagedResponse> listLocationsPagedCallable()
Lists information about the supported locations for this service.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListLocationsRequest request = ListLocationsRequest.newBuilder() .setName("name3373707") .setFilter("filter-1274492040") .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); ApiFuture<Location> future = cloudTasksClient.listLocationsPagedCallable().futureCall(request); // Do something. for (Location element : future.get().iterateAll()) { // doThingsWith(element); } }
-
listLocationsCallable
public final com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,com.google.cloud.location.ListLocationsResponse> listLocationsCallable()
Lists information about the supported locations for this service.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { ListLocationsRequest request = ListLocationsRequest.newBuilder() .setName("name3373707") .setFilter("filter-1274492040") .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); while (true) { ListLocationsResponse response = cloudTasksClient.listLocationsCallable().call(request); for (Location element : response.getLocationsList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } }
-
getLocation
public final com.google.cloud.location.Location getLocation(com.google.cloud.location.GetLocationRequest request)
Gets information about a location.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); Location response = cloudTasksClient.getLocation(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getLocationCallable
public final com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.GetLocationRequest,com.google.cloud.location.Location> getLocationCallable()
Gets information about a location.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); ApiFuture<Location> future = cloudTasksClient.getLocationCallable().futureCall(request); // Do something. Location response = future.get(); }
-
close
public final void close()
- Specified by:
close
in interfaceAutoCloseable
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacecom.google.api.gax.core.BackgroundResource
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfacecom.google.api.gax.core.BackgroundResource
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfacecom.google.api.gax.core.BackgroundResource
-
shutdownNow
public void shutdownNow()
- Specified by:
shutdownNow
in interfacecom.google.api.gax.core.BackgroundResource
-
awaitTermination
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfacecom.google.api.gax.core.BackgroundResource
- Throws:
InterruptedException
-
-