Class CloudTasksClient (2.3.3)

public class CloudTasksClient implements 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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:

  1. 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.
  2. 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.
  3. 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 CloudTasksSettings cloudTasksSettings =
     CloudTasksSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 CloudTasksSettings cloudTasksSettings =
     CloudTasksSettings.newBuilder()
         .setTransportChannelProvider(
             CloudTasksSettings.defaultHttpJsonTransportProviderBuilder().build())
         .build();
 CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > CloudTasksClient

Implements

BackgroundResource

Static Methods

create()

public static final CloudTasksClient create()

Constructs an instance of CloudTasksClient with default settings.

Returns
TypeDescription
CloudTasksClient
Exceptions
TypeDescription
IOException

create(CloudTasksSettings settings)

public static final CloudTasksClient create(CloudTasksSettings settings)

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.

Parameter
NameDescription
settingsCloudTasksSettings
Returns
TypeDescription
CloudTasksClient
Exceptions
TypeDescription
IOException

create(CloudTasksStub stub)

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).

Parameter
NameDescription
stubCloudTasksStub
Returns
TypeDescription
CloudTasksClient

Constructors

CloudTasksClient(CloudTasksSettings settings)

protected CloudTasksClient(CloudTasksSettings settings)

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.

Parameter
NameDescription
settingsCloudTasksSettings

CloudTasksClient(CloudTasksStub stub)

protected CloudTasksClient(CloudTasksStub stub)
Parameter
NameDescription
stubCloudTasksStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

createQueue(CreateQueueRequest request)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
 }
 
Parameter
NameDescription
requestCreateQueueRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Queue

createQueue(LocationName parent, Queue queue)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   Queue queue = Queue.newBuilder().build();
   Queue response = cloudTasksClient.createQueue(parent, queue);
 }
 
Parameters
NameDescription
parentLocationName

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.

queueQueue

Required. The queue to create.

Queue's name cannot be the same as an existing queue.

Returns
TypeDescription
Queue

createQueue(String parent, Queue queue)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   Queue queue = Queue.newBuilder().build();
   Queue response = cloudTasksClient.createQueue(parent, queue);
 }
 
Parameters
NameDescription
parentString

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.

queueQueue

Required. The queue to create.

Queue's name cannot be the same as an existing queue.

Returns
TypeDescription
Queue

createQueueCallable()

public final 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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<CreateQueueRequest,Queue>

createTask(CreateTaskRequest request)

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.

  • The maximum task size is 100KB.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
 }
 
Parameter
NameDescription
requestCreateTaskRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Task

createTask(QueueName parent, Task task)

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.

  • The maximum task size is 100KB.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Task task = Task.newBuilder().build();
   Task response = cloudTasksClient.createTask(parent, task);
 }
 
Parameters
NameDescription
parentQueueName

Required. The queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

The queue must already exist.

taskTask

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. 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.

If 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 executed recently then the call will fail with ALREADY_EXISTS. If the task's queue was created using Cloud Tasks, then another task with the same name can't be created for ~1hour after the original task was deleted or executed. 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 ~9days after the original task was deleted or executed.

Because there is an extra lookup cost to identify duplicate task names, these 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.

Returns
TypeDescription
Task

createTask(String parent, Task task)

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.

  • The maximum task size is 100KB.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
NameDescription
parentString

Required. The queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

The queue must already exist.

taskTask

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. 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.

If 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 executed recently then the call will fail with ALREADY_EXISTS. If the task's queue was created using Cloud Tasks, then another task with the same name can't be created for ~1hour after the original task was deleted or executed. 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 ~9days after the original task was deleted or executed.

Because there is an extra lookup cost to identify duplicate task names, these 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.

Returns
TypeDescription
Task

createTaskCallable()

public final UnaryCallable<CreateTaskRequest,Task> createTaskCallable()

Creates a task and adds it to a queue.

Tasks cannot be updated after creation; there is no UpdateTask command.

  • The maximum task size is 100KB.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<CreateTaskRequest,Task>

deleteQueue(DeleteQueueRequest request)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   DeleteQueueRequest request =
       DeleteQueueRequest.newBuilder()
           .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString())
           .build();
   cloudTasksClient.deleteQueue(request);
 }
 
Parameter
NameDescription
requestDeleteQueueRequest

The request object containing all of the parameters for the API call.

deleteQueue(QueueName name)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   cloudTasksClient.deleteQueue(name);
 }
 
Parameter
NameDescription
nameQueueName

Required. The queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

deleteQueue(String name)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   cloudTasksClient.deleteQueue(name);
 }
 
Parameter
NameDescription
nameString

Required. The queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

deleteQueueCallable()

public final UnaryCallable<DeleteQueueRequest,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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteQueueRequest,Empty>

deleteTask(DeleteTaskRequest request)

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 executed successfully or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   DeleteTaskRequest request =
       DeleteTaskRequest.newBuilder()
           .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString())
           .build();
   cloudTasksClient.deleteTask(request);
 }
 
Parameter
NameDescription
requestDeleteTaskRequest

The request object containing all of the parameters for the API call.

deleteTask(TaskName name)

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 executed successfully or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
   cloudTasksClient.deleteTask(name);
 }
 
Parameter
NameDescription
nameTaskName

Required. The task name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID

deleteTask(String name)

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 executed successfully or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString();
   cloudTasksClient.deleteTask(name);
 }
 
Parameter
NameDescription
nameString

Required. The task name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID

deleteTaskCallable()

public final UnaryCallable<DeleteTaskRequest,Empty> deleteTaskCallable()

Deletes a task.

A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has executed successfully or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteTaskRequest,Empty>

getIamPolicy(ResourceName resource)

public final Policy getIamPolicy(ResourceName resource)

Gets the access control policy for a Queue. Returns an empty policy if the resource exists and does not have a policy set.

Authorization requires the following Google IAM permission on the specified resource parent:

  • cloudtasks.queues.getIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Policy response = cloudTasksClient.getIamPolicy(resource);
 }
 
Parameter
NameDescription
resourcecom.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicy(QueueName queueName)

public final Policy getIamPolicy(QueueName queueName)
Parameter
NameDescription
queueNameQueueName
Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicy(GetIamPolicyRequest request)

public final Policy getIamPolicy(GetIamPolicyRequest request)

Gets the access control policy for a Queue. Returns an empty policy if the resource exists and does not have a policy set.

Authorization requires the following Google IAM permission on the specified resource parent:

  • cloudtasks.queues.getIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.GetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicy(String resource)

public final Policy getIamPolicy(String resource)

Gets the access control policy for a Queue. Returns an empty policy if the resource exists and does not have a policy set.

Authorization requires the following Google IAM permission on the specified resource parent:

  • cloudtasks.queues.getIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   Policy response = cloudTasksClient.getIamPolicy(resource);
 }
 
Parameter
NameDescription
resourceString

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicyCallable()

public final UnaryCallable<GetIamPolicyRequest,Policy> getIamPolicyCallable()

Gets the access control policy for a Queue. Returns an empty policy if the resource exists and does not have a policy set.

Authorization requires the following Google IAM permission on the specified resource parent:

  • cloudtasks.queues.getIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getQueue(GetQueueRequest request)

public final Queue getQueue(GetQueueRequest request)

Gets a queue.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   GetQueueRequest request =
       GetQueueRequest.newBuilder()
           .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString())
           .build();
   Queue response = cloudTasksClient.getQueue(request);
 }
 
Parameter
NameDescription
requestGetQueueRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Queue

getQueue(QueueName name)

public final Queue getQueue(QueueName name)

Gets a queue.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Queue response = cloudTasksClient.getQueue(name);
 }
 
Parameter
NameDescription
nameQueueName

Required. The resource name of the queue. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

getQueue(String name)

public final Queue getQueue(String name)

Gets a queue.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   Queue response = cloudTasksClient.getQueue(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the queue. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

getQueueCallable()

public final UnaryCallable<GetQueueRequest,Queue> getQueueCallable()

Gets a queue.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   GetQueueRequest request =
       GetQueueRequest.newBuilder()
           .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString())
           .build();
   ApiFuture<Queue> future = cloudTasksClient.getQueueCallable().futureCall(request);
   // Do something.
   Queue response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetQueueRequest,Queue>

getSettings()

public final CloudTasksSettings getSettings()
Returns
TypeDescription
CloudTasksSettings

getStub()

public CloudTasksStub getStub()
Returns
TypeDescription
CloudTasksStub

getTask(GetTaskRequest request)

public final Task getTask(GetTaskRequest request)

Gets a task.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   GetTaskRequest request =
       GetTaskRequest.newBuilder()
           .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString())
           .build();
   Task response = cloudTasksClient.getTask(request);
 }
 
Parameter
NameDescription
requestGetTaskRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Task

getTask(TaskName name)

public final Task getTask(TaskName name)

Gets a task.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
   Task response = cloudTasksClient.getTask(name);
 }
 
Parameter
NameDescription
nameTaskName

Required. The task name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID

Returns
TypeDescription
Task

getTask(String name)

public final Task getTask(String name)

Gets a task.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString();
   Task response = cloudTasksClient.getTask(name);
 }
 
Parameter
NameDescription
nameString

Required. The task name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID

Returns
TypeDescription
Task

getTaskCallable()

public final UnaryCallable<GetTaskRequest,Task> getTaskCallable()

Gets a task.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<GetTaskRequest,Task>

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listQueues(ListQueuesRequest request)

public final CloudTasksClient.ListQueuesPagedResponse listQueues(ListQueuesRequest request)

Lists queues.

Queues are returned in lexicographical order.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ListQueuesRequest request =
       ListQueuesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Queue element : cloudTasksClient.listQueues(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListQueuesRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
CloudTasksClient.ListQueuesPagedResponse

listQueues(LocationName parent)

public final CloudTasksClient.ListQueuesPagedResponse listQueues(LocationName parent)

Lists queues.

Queues are returned in lexicographical order.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   for (Queue element : cloudTasksClient.listQueues(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentLocationName

Required. The location name. For example: projects/PROJECT_ID/locations/LOCATION_ID

Returns
TypeDescription
CloudTasksClient.ListQueuesPagedResponse

listQueues(String parent)

public final CloudTasksClient.ListQueuesPagedResponse listQueues(String parent)

Lists queues.

Queues are returned in lexicographical order.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   for (Queue element : cloudTasksClient.listQueues(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The location name. For example: projects/PROJECT_ID/locations/LOCATION_ID

Returns
TypeDescription
CloudTasksClient.ListQueuesPagedResponse

listQueuesCallable()

public final UnaryCallable<ListQueuesRequest,ListQueuesResponse> listQueuesCallable()

Lists queues.

Queues are returned in lexicographical order.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ListQueuesRequest request =
       ListQueuesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .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;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListQueuesRequest,ListQueuesResponse>

listQueuesPagedCallable()

public final UnaryCallable<ListQueuesRequest,CloudTasksClient.ListQueuesPagedResponse> listQueuesPagedCallable()

Lists queues.

Queues are returned in lexicographical order.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ListQueuesRequest request =
       ListQueuesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Queue> future = cloudTasksClient.listQueuesPagedCallable().futureCall(request);
   // Do something.
   for (Queue element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListQueuesRequest,ListQueuesPagedResponse>

listTasks(ListTasksRequest request)

public final CloudTasksClient.ListTasksPagedResponse listTasks(ListTasksRequest request)

Lists the tasks in a queue.

By default, only the BASIC view is retrieved due to performance considerations; 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
   }
 }
 
Parameter
NameDescription
requestListTasksRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
CloudTasksClient.ListTasksPagedResponse

listTasks(QueueName parent)

public final CloudTasksClient.ListTasksPagedResponse listTasks(QueueName parent)

Lists the tasks in a queue.

By default, only the BASIC view is retrieved due to performance considerations; 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   for (Task element : cloudTasksClient.listTasks(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentQueueName

Required. The queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
CloudTasksClient.ListTasksPagedResponse

listTasks(String parent)

public final CloudTasksClient.ListTasksPagedResponse listTasks(String parent)

Lists the tasks in a queue.

By default, only the BASIC view is retrieved due to performance considerations; 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   for (Task element : cloudTasksClient.listTasks(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The queue name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
CloudTasksClient.ListTasksPagedResponse

listTasksCallable()

public final UnaryCallable<ListTasksRequest,ListTasksResponse> listTasksCallable()

Lists the tasks in a queue.

By default, only the BASIC view is retrieved due to performance considerations; 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListTasksRequest,ListTasksResponse>

listTasksPagedCallable()

public final UnaryCallable<ListTasksRequest,CloudTasksClient.ListTasksPagedResponse> listTasksPagedCallable()

Lists the tasks in a queue.

By default, only the BASIC view is retrieved due to performance considerations; 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListTasksRequest,ListTasksPagedResponse>

pauseQueue(PauseQueueRequest request)

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. Tasks can still be added when the queue is paused. A queue is paused if its state is PAUSED.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   PauseQueueRequest request =
       PauseQueueRequest.newBuilder()
           .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString())
           .build();
   Queue response = cloudTasksClient.pauseQueue(request);
 }
 
Parameter
NameDescription
requestPauseQueueRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Queue

pauseQueue(QueueName name)

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. Tasks can still be added when the queue is paused. A queue is paused if its state is PAUSED.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Queue response = cloudTasksClient.pauseQueue(name);
 }
 
Parameter
NameDescription
nameQueueName

Required. The queue name. For example: projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

pauseQueue(String name)

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. Tasks can still be added when the queue is paused. A queue is paused if its state is PAUSED.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   Queue response = cloudTasksClient.pauseQueue(name);
 }
 
Parameter
NameDescription
nameString

Required. The queue name. For example: projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

pauseQueueCallable()

public final 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. Tasks can still be added when the queue is paused. A queue is paused if its state is PAUSED.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<PauseQueueRequest,Queue>

purgeQueue(PurgeQueueRequest request)

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   PurgeQueueRequest request =
       PurgeQueueRequest.newBuilder()
           .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString())
           .build();
   Queue response = cloudTasksClient.purgeQueue(request);
 }
 
Parameter
NameDescription
requestPurgeQueueRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Queue

purgeQueue(QueueName name)

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Queue response = cloudTasksClient.purgeQueue(name);
 }
 
Parameter
NameDescription
nameQueueName

Required. The queue name. For example: projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

purgeQueue(String name)

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   Queue response = cloudTasksClient.purgeQueue(name);
 }
 
Parameter
NameDescription
nameString

Required. The queue name. For example: projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

purgeQueueCallable()

public final 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<PurgeQueueRequest,Queue>

resumeQueue(QueueName name)

public final Queue resumeQueue(QueueName name)

Resume a queue.

This method resumes a queue after it has been PAUSED or DISABLED. The state of a queue is stored in the queue's state; after calling this method it will be set to 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.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Queue response = cloudTasksClient.resumeQueue(name);
 }
 
Parameter
NameDescription
nameQueueName

Required. The queue name. For example: projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

resumeQueue(ResumeQueueRequest request)

public final Queue resumeQueue(ResumeQueueRequest request)

Resume a queue.

This method resumes a queue after it has been PAUSED or DISABLED. The state of a queue is stored in the queue's state; after calling this method it will be set to 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.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ResumeQueueRequest request =
       ResumeQueueRequest.newBuilder()
           .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString())
           .build();
   Queue response = cloudTasksClient.resumeQueue(request);
 }
 
Parameter
NameDescription
requestResumeQueueRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Queue

resumeQueue(String name)

public final Queue resumeQueue(String name)

Resume a queue.

This method resumes a queue after it has been PAUSED or DISABLED. The state of a queue is stored in the queue's state; after calling this method it will be set to 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.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   Queue response = cloudTasksClient.resumeQueue(name);
 }
 
Parameter
NameDescription
nameString

Required. The queue name. For example: projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID

Returns
TypeDescription
Queue

resumeQueueCallable()

public final UnaryCallable<ResumeQueueRequest,Queue> resumeQueueCallable()

Resume a queue.

This method resumes a queue after it has been PAUSED or DISABLED. The state of a queue is stored in the queue's state; after calling this method it will be set to 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.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<ResumeQueueRequest,Queue>

runTask(RunTaskRequest request)

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 or is PAUSED.

This command is meant to be used for manual debugging. For example, 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 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 will be reset to the time that RunTask was called plus the retry delay specified in the queue's RetryConfig.

RunTask returns NOT_FOUND when it is called on a task that has already succeeded or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   RunTaskRequest request =
       RunTaskRequest.newBuilder()
           .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString())
           .build();
   Task response = cloudTasksClient.runTask(request);
 }
 
Parameter
NameDescription
requestRunTaskRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Task

runTask(TaskName name)

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 or is PAUSED.

This command is meant to be used for manual debugging. For example, 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 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 will be reset to the time that RunTask was called plus the retry delay specified in the queue's RetryConfig.

RunTask returns NOT_FOUND when it is called on a task that has already succeeded or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
   Task response = cloudTasksClient.runTask(name);
 }
 
Parameter
NameDescription
nameTaskName

Required. The task name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID

Returns
TypeDescription
Task

runTask(String name)

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 or is PAUSED.

This command is meant to be used for manual debugging. For example, 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 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 will be reset to the time that RunTask was called plus the retry delay specified in the queue's RetryConfig.

RunTask returns NOT_FOUND when it is called on a task that has already succeeded or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString();
   Task response = cloudTasksClient.runTask(name);
 }
 
Parameter
NameDescription
nameString

Required. The task name. For example: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID

Returns
TypeDescription
Task

runTaskCallable()

public final 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 or is PAUSED.

This command is meant to be used for manual debugging. For example, 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 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 will be reset to the time that RunTask was called plus the retry delay specified in the queue's RetryConfig.

RunTask returns NOT_FOUND when it is called on a task that has already succeeded or permanently failed.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<RunTaskRequest,Task>

setIamPolicy(ResourceName resource, Policy policy)

public final Policy setIamPolicy(ResourceName resource, Policy policy)

Sets the access control policy for a 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 permission on the specified resource parent:

  • cloudtasks.queues.setIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   Policy policy = Policy.newBuilder().build();
   Policy response = cloudTasksClient.setIamPolicy(resource, policy);
 }
 
Parameters
NameDescription
resourcecom.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policycom.google.iam.v1.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.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicy(QueueName queue, Policy policy)

public final Policy setIamPolicy(QueueName queue, Policy policy)
Parameters
NameDescription
queueQueueName
policycom.google.iam.v1.Policy
Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicy(SetIamPolicyRequest request)

public final Policy setIamPolicy(SetIamPolicyRequest request)

Sets the access control policy for a 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 permission on the specified resource parent:

  • cloudtasks.queues.setIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.SetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicy(String resource, Policy policy)

public final Policy setIamPolicy(String resource, Policy policy)

Sets the access control policy for a 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 permission on the specified resource parent:

  • cloudtasks.queues.setIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   Policy policy = Policy.newBuilder().build();
   Policy response = cloudTasksClient.setIamPolicy(resource, policy);
 }
 
Parameters
NameDescription
resourceString

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policycom.google.iam.v1.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.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicyCallable()

public final UnaryCallable<SetIamPolicyRequest,Policy> setIamPolicyCallable()

Sets the access control policy for a 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 permission on the specified resource parent:

  • cloudtasks.queues.setIamPolicy

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

testIamPermissions(ResourceName resource, List<String> permissions)

public final TestIamPermissionsResponse testIamPermissions(ResourceName resource, List<String> permissions)

Returns permissions that a caller has on a Queue. If the resource does not exist, this will return an empty set of permissions, not a 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
   List<String> permissions = new ArrayList<>();
   TestIamPermissionsResponse response =
       cloudTasksClient.testIamPermissions(resource, permissions);
 }
 
Parameters
NameDescription
resourcecom.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissionsList<String>

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.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(QueueName queue, List<String> permissions)

public final TestIamPermissionsResponse testIamPermissions(QueueName queue, List<String> permissions)
Parameters
NameDescription
queueQueueName
permissionsList<String>
Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(TestIamPermissionsRequest request)

public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request)

Returns permissions that a caller has on a Queue. If the resource does not exist, this will return an empty set of permissions, not a 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.TestIamPermissionsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(String resource, List<String> permissions)

public final TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)

Returns permissions that a caller has on a Queue. If the resource does not exist, this will return an empty set of permissions, not a 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   String resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString();
   List<String> permissions = new ArrayList<>();
   TestIamPermissionsResponse response =
       cloudTasksClient.testIamPermissions(resource, permissions);
 }
 
Parameters
NameDescription
resourceString

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissionsList<String>

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.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissionsCallable()

public final UnaryCallable<TestIamPermissionsRequest,TestIamPermissionsResponse> testIamPermissionsCallable()

Returns permissions that a caller has on a Queue. If the resource does not exist, this will return an empty set of permissions, not a 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>

updateQueue(Queue queue, FieldMask updateMask)

public final Queue updateQueue(Queue queue, 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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   Queue queue = Queue.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Queue response = cloudTasksClient.updateQueue(queue, updateMask);
 }
 
Parameters
NameDescription
queueQueue

Required. The queue to create or update.

The queue's 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 cannot be changed.

updateMaskFieldMask

A mask used to specify which fields of the queue are being updated.

If empty, then all fields will be updated.

Returns
TypeDescription
Queue

updateQueue(UpdateQueueRequest request)

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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
   UpdateQueueRequest request =
       UpdateQueueRequest.newBuilder()
           .setQueue(Queue.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Queue response = cloudTasksClient.updateQueue(request);
 }
 
Parameter
NameDescription
requestUpdateQueueRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Queue

updateQueueCallable()

public final 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 before using this method.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateQueueRequest,Queue>