Google Cloud Tasks V2 Client - Class CloudTasksClient (1.12.2)

Reference documentation and code samples for the Google Cloud Tasks V2 Client class CloudTasksClient.

Service Description: Cloud Tasks allows developers to manage the execution of background work in their applications.

This class is currently experimental and may be subject to changes.

Namespace

Google \ Cloud \ Tasks \ V2 \ Client

Methods

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

createQueue

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::createQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\CreateQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Queue

createTask

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::createTaskAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\CreateTaskRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Task

deleteQueue

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::deleteQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\DeleteQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

deleteTask

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::deleteTaskAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\DeleteTaskRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

getIamPolicy

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

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::getIamPolicyAsync() .

Parameters
NameDescription
request Google\Cloud\Iam\V1\GetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy

getQueue

Gets a queue.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::getQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\GetQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Queue

getTask

Gets a task.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::getTaskAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\GetTaskRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Task

listQueues

Lists queues.

Queues are returned in lexicographical order.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::listQueuesAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\ListQueuesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

listTasks

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::listTasksAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\ListTasksRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

pauseQueue

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::pauseQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\PauseQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Queue

purgeQueue

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::purgeQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\PurgeQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Queue

resumeQueue

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::resumeQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\ResumeQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Queue

runTask

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::runTaskAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\RunTaskRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Task

setIamPolicy

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

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::setIamPolicyAsync() .

Parameters
NameDescription
request Google\Cloud\Iam\V1\SetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy

testIamPermissions

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::testIamPermissionsAsync() .

Parameters
NameDescription
request Google\Cloud\Iam\V1\TestIamPermissionsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\TestIamPermissionsResponse

updateQueue

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.

The async variant is Google\Cloud\Tasks\V2\Client\BaseClient\self::updateQueueAsync() .

Parameters
NameDescription
request Google\Cloud\Tasks\V2\UpdateQueueRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Tasks\V2\Queue

createQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\CreateQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

createTaskAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\CreateTaskRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

deleteQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\DeleteQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

deleteTaskAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\DeleteTaskRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

getIamPolicyAsync

Parameters
NameDescription
request Google\Cloud\Iam\V1\GetIamPolicyRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

getQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\GetQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

getTaskAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\GetTaskRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

listQueuesAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\ListQueuesRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

listTasksAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\ListTasksRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

pauseQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\PauseQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

purgeQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\PurgeQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

resumeQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\ResumeQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

runTaskAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\RunTaskRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

setIamPolicyAsync

Parameters
NameDescription
request Google\Cloud\Iam\V1\SetIamPolicyRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

testIamPermissionsAsync

Parameters
NameDescription
request Google\Cloud\Iam\V1\TestIamPermissionsRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

updateQueueAsync

Parameters
NameDescription
request Google\Cloud\Tasks\V2\UpdateQueueRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

static::locationName

Formats a string containing the fully-qualified path to represent a location resource.

Parameters
NameDescription
project string
location string
Returns
TypeDescription
stringThe formatted location resource.

static::queueName

Formats a string containing the fully-qualified path to represent a queue resource.

Parameters
NameDescription
project string
location string
queue string
Returns
TypeDescription
stringThe formatted queue resource.

static::taskName

Formats a string containing the fully-qualified path to represent a task resource.

Parameters
NameDescription
project string
location string
queue string
task string
Returns
TypeDescription
stringThe formatted task resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • location: projects/{project}/locations/{location}
  • queue: projects/{project}/locations/{location}/queues/{queue}
  • task: projects/{project}/locations/{location}/queues/{queue}/tasks/{task}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.