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 provides the ability to make remote calls to the backing service through method calls that map to API methods.
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 parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
Namespace
Google \ Cloud \ Tasks \ V2 \ ClientMethods
__construct
Constructor.
| Parameters | |
|---|---|
| Name | Description |
options |
array|Google\ApiCore\Options\ClientOptions
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 |
Google\Auth\FetchAuthTokenInterface|Google\ApiCore\CredentialsWrapper
This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly |
↳ 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 |
↳ 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|Google\ApiCore\Transport\TransportInterface
The transport used for executing network requests. May be either the string |
↳ 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. |
↳ logger |
false|Psr\Log\LoggerInterface
A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag |
↳ universeDomain |
string
The service domain for the client. Defaults to 'googleapis.com'. |
batchCreateTasks
Creates a batch of tasks and adds them to a queue.
All tasks must be for the same queue. A maximum of 100 tasks can be created in a single batch.
The async variant is CloudTasksClient::batchCreateTasksAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\BatchCreateTasksRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse<Google\Cloud\Tasks\V2\BatchCreateTasksResponse> |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tasks\V2\BatchCreateTasksRequest;
use Google\Cloud\Tasks\V2\BatchCreateTasksResponse;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\CreateTaskRequest;
use Google\Cloud\Tasks\V2\Task;
use Google\Rpc\Status;
/**
* @param string $formattedParent The queue name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
*
* The queue must already exist. Please see
* {@see CloudTasksClient::queueName()} for help formatting this field.
* @param string $formattedRequestsParent The queue name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
*
* The queue must already exist. Please see
* {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function batch_create_tasks_sample(string $formattedParent, string $formattedRequestsParent): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$requestsTask = new Task();
$createTaskRequest = (new CreateTaskRequest())
->setParent($formattedRequestsParent)
->setTask($requestsTask);
$requests = [$createTaskRequest,];
$request = (new BatchCreateTasksRequest())
->setParent($formattedParent)
->setRequests($requests);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudTasksClient->batchCreateTasks($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var BatchCreateTasksResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
$formattedRequestsParent = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
batch_create_tasks_sample($formattedParent, $formattedRequestsParent);
}
batchDeleteTasks
Deletes a batch of tasks.
This is a non-atomic operation: if deletion fails for some tasks, it can still succeed for others. The metadata field of google.longrunning.Operation contains details of failed deletions. A maximum of 1000 tasks can be deleted in a batch.
The async variant is CloudTasksClient::batchDeleteTasksAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\BatchDeleteTasksRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse<null> |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tasks\V2\BatchDeleteTasksRequest;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Rpc\Status;
/**
* @param string $formattedParent The queue name. For example:
* Format: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
* @param string $formattedNamesElement The names of the tasks to delete.
* A maximum of 1000 tasks can be deleted in a batch.
* For example:
* Format:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
* Please see {@see CloudTasksClient::taskName()} for help formatting this field.
*/
function batch_delete_tasks_sample(string $formattedParent, string $formattedNamesElement): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$formattedNames = [$formattedNamesElement,];
$request = (new BatchDeleteTasksRequest())
->setParent($formattedParent)
->setNames($formattedNames);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudTasksClient->batchDeleteTasks($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
$formattedNamesElement = CloudTasksClient::taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
batch_delete_tasks_sample($formattedParent, $formattedNamesElement);
}
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 CloudTasksClient::createQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\CreateQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Queue |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\CreateQueueRequest;
use Google\Cloud\Tasks\V2\Queue;
/**
* @param string $formattedParent The location name in which the queue will be created.
* For example: `projects/PROJECT_ID/locations/LOCATION_ID`
*
* The list of allowed locations can be obtained by calling Cloud
* Tasks' implementation of
* [ListLocations][google.cloud.location.Locations.ListLocations]. Please see
* {@see CloudTasksClient::locationName()} for help formatting this field.
*/
function create_queue_sample(string $formattedParent): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$queue = new Queue();
$request = (new CreateQueueRequest())
->setParent($formattedParent)
->setQueue($queue);
// Call the API and handle any network failures.
try {
/** @var Queue $response */
$response = $cloudTasksClient->createQueue($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudTasksClient::locationName('[PROJECT]', '[LOCATION]');
create_queue_sample($formattedParent);
}
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 CloudTasksClient::createTaskAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\CreateTaskRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Task |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\CreateTaskRequest;
use Google\Cloud\Tasks\V2\Task;
/**
* @param string $formattedParent The queue name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
*
* The queue must already exist. Please see
* {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function create_task_sample(string $formattedParent): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$task = new Task();
$request = (new CreateTaskRequest())
->setParent($formattedParent)
->setTask($task);
// Call the API and handle any network failures.
try {
/** @var Task $response */
$response = $cloudTasksClient->createTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
create_task_sample($formattedParent);
}
deleteQueue
Deletes a queue.
This command will delete the queue even if it has tasks in it.
Note: If you delete a queue, you may be prevented from creating a new queue with the same name as the deleted queue for a tombstone window of up to 3 days. During this window, the CreateQueue operation may appear to recreate the queue, but this can be misleading. If you attempt to create a queue with the same name as one that is in the tombstone window, run GetQueue to confirm that the queue creation was successful. If GetQueue returns 200 response code, your queue was successfully created with the name of the previously deleted queue. Otherwise, your queue did not successfully recreate.
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 CloudTasksClient::deleteQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\DeleteQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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. |
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\DeleteQueueRequest;
/**
* @param string $formattedName The queue name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function delete_queue_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new DeleteQueueRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
$cloudTasksClient->deleteQueue($request);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
delete_queue_sample($formattedName);
}
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 CloudTasksClient::deleteTaskAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\DeleteTaskRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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. |
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\DeleteTaskRequest;
/**
* @param string $formattedName The task name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
* Please see {@see CloudTasksClient::taskName()} for help formatting this field.
*/
function delete_task_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new DeleteTaskRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
$cloudTasksClient->deleteTask($request);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
delete_task_sample($formattedName);
}
getCmekConfig
Gets the CMEK config.
Gets the Customer Managed Encryption Key configured with the Cloud Tasks location. By default there is no kms_key configured.
The async variant is CloudTasksClient::getCmekConfigAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\GetCmekConfigRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\CmekConfig |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\CmekConfig;
use Google\Cloud\Tasks\V2\GetCmekConfigRequest;
/**
* @param string $formattedName The config. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/CmekConfig`
* Please see {@see CloudTasksClient::cmekConfigName()} for help formatting this field.
*/
function get_cmek_config_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new GetCmekConfigRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var CmekConfig $response */
$response = $cloudTasksClient->getCmekConfig($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::cmekConfigName('[PROJECT]', '[LOCATION]');
get_cmek_config_sample($formattedName);
}
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 CloudTasksClient::getIamPolicyAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V1\GetIamPolicyRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Iam\V1\Policy |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
use Google\Cloud\Iam\V1\Policy;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
/**
* @param string $resource REQUIRED: The resource for which the policy is being requested.
* See the operation documentation for the appropriate value for this field.
*/
function get_iam_policy_sample(string $resource): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new GetIamPolicyRequest())
->setResource($resource);
// Call the API and handle any network failures.
try {
/** @var Policy $response */
$response = $cloudTasksClient->getIamPolicy($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$resource = '[RESOURCE]';
get_iam_policy_sample($resource);
}
getQueue
Gets a queue.
The async variant is CloudTasksClient::getQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\GetQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Queue |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\GetQueueRequest;
use Google\Cloud\Tasks\V2\Queue;
/**
* @param string $formattedName The resource name of the queue. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function get_queue_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new GetQueueRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Queue $response */
$response = $cloudTasksClient->getQueue($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
get_queue_sample($formattedName);
}
getTask
Gets a task.
After a task is successfully executed or has exhausted its retry attempts,
the task is deleted. A GetTask request for a deleted task returns a
NOT_FOUND error.
The async variant is CloudTasksClient::getTaskAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\GetTaskRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Task |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\GetTaskRequest;
use Google\Cloud\Tasks\V2\Task;
/**
* @param string $formattedName The task name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
* Please see {@see CloudTasksClient::taskName()} for help formatting this field.
*/
function get_task_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new GetTaskRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Task $response */
$response = $cloudTasksClient->getTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
get_task_sample($formattedName);
}
listQueues
Lists queues.
Queues are returned in lexicographical order.
The async variant is CloudTasksClient::listQueuesAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\ListQueuesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\ListQueuesRequest;
use Google\Cloud\Tasks\V2\Queue;
/**
* @param string $formattedParent The location name.
* For example: `projects/PROJECT_ID/locations/LOCATION_ID`
* Please see {@see CloudTasksClient::locationName()} for help formatting this field.
*/
function list_queues_sample(string $formattedParent): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new ListQueuesRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudTasksClient->listQueues($request);
/** @var Queue $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudTasksClient::locationName('[PROJECT]', '[LOCATION]');
list_queues_sample($formattedParent);
}
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 CloudTasksClient::listTasksAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\ListTasksRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\ListTasksRequest;
use Google\Cloud\Tasks\V2\Task;
/**
* @param string $formattedParent The queue name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function list_tasks_sample(string $formattedParent): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new ListTasksRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudTasksClient->listTasks($request);
/** @var Task $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
list_tasks_sample($formattedParent);
}
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 CloudTasksClient::pauseQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\PauseQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Queue |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\PauseQueueRequest;
use Google\Cloud\Tasks\V2\Queue;
/**
* @param string $formattedName The queue name. For example:
* `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function pause_queue_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new PauseQueueRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Queue $response */
$response = $cloudTasksClient->pauseQueue($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
pause_queue_sample($formattedName);
}
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 CloudTasksClient::purgeQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\PurgeQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Queue |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\PurgeQueueRequest;
use Google\Cloud\Tasks\V2\Queue;
/**
* @param string $formattedName The queue name. For example:
* `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function purge_queue_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new PurgeQueueRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Queue $response */
$response = $cloudTasksClient->purgeQueue($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
purge_queue_sample($formattedName);
}
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 CloudTasksClient::resumeQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\ResumeQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Queue |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\Queue;
use Google\Cloud\Tasks\V2\ResumeQueueRequest;
/**
* @param string $formattedName The queue name. For example:
* `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`
* Please see {@see CloudTasksClient::queueName()} for help formatting this field.
*/
function resume_queue_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new ResumeQueueRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Queue $response */
$response = $cloudTasksClient->resumeQueue($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::queueName('[PROJECT]', '[LOCATION]', '[QUEUE]');
resume_queue_sample($formattedName);
}
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.
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 CloudTasksClient::runTaskAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\RunTaskRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Task |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\RunTaskRequest;
use Google\Cloud\Tasks\V2\Task;
/**
* @param string $formattedName The task name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
* Please see {@see CloudTasksClient::taskName()} for help formatting this field.
*/
function run_task_sample(string $formattedName): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = (new RunTaskRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Task $response */
$response = $cloudTasksClient->runTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudTasksClient::taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
run_task_sample($formattedName);
}
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 CloudTasksClient::setIamPolicyAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V1\SetIamPolicyRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Iam\V1\Policy |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V1\Policy;
use Google\Cloud\Iam\V1\SetIamPolicyRequest;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
/**
* @param string $resource REQUIRED: The resource for which the policy is being specified.
* See the operation documentation for the appropriate value for this field.
*/
function set_iam_policy_sample(string $resource): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$policy = new Policy();
$request = (new SetIamPolicyRequest())
->setResource($resource)
->setPolicy($policy);
// Call the API and handle any network failures.
try {
/** @var Policy $response */
$response = $cloudTasksClient->setIamPolicy($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$resource = '[RESOURCE]';
set_iam_policy_sample($resource);
}
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 CloudTasksClient::testIamPermissionsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V1\TestIamPermissionsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Iam\V1\TestIamPermissionsResponse |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V1\TestIamPermissionsRequest;
use Google\Cloud\Iam\V1\TestIamPermissionsResponse;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
/**
* @param string $resource REQUIRED: The resource for which the policy detail is being requested.
* See the operation documentation for the appropriate value for this field.
* @param string $permissionsElement The set of permissions to check for the `resource`. Permissions with
* wildcards (such as '*' or 'storage.*') are not allowed. For more
* information see
* [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
*/
function test_iam_permissions_sample(string $resource, string $permissionsElement): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$permissions = [$permissionsElement,];
$request = (new TestIamPermissionsRequest())
->setResource($resource)
->setPermissions($permissions);
// Call the API and handle any network failures.
try {
/** @var TestIamPermissionsResponse $response */
$response = $cloudTasksClient->testIamPermissions($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$resource = '[RESOURCE]';
$permissionsElement = '[PERMISSIONS]';
test_iam_permissions_sample($resource, $permissionsElement);
}
updateCmekConfig
Creates or Updates a CMEK config.
Updates the Customer Managed Encryption Key associated with the Cloud Tasks location (Creates if the key does not already exist). All new tasks created in the location will be encrypted at-rest with the KMS-key provided in the config.
The async variant is CloudTasksClient::updateCmekConfigAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\UpdateCmekConfigRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\CmekConfig |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\CmekConfig;
use Google\Cloud\Tasks\V2\UpdateCmekConfigRequest;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_cmek_config_sample(): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$cmekConfig = new CmekConfig();
$request = (new UpdateCmekConfigRequest())
->setCmekConfig($cmekConfig);
// Call the API and handle any network failures.
try {
/** @var CmekConfig $response */
$response = $cloudTasksClient->updateCmekConfig($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
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 CloudTasksClient::updateQueueAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\UpdateQueueRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Tasks\V2\Queue |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
use Google\Cloud\Tasks\V2\Queue;
use Google\Cloud\Tasks\V2\UpdateQueueRequest;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_queue_sample(): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$queue = new Queue();
$request = (new UpdateQueueRequest())
->setQueue($queue);
// Call the API and handle any network failures.
try {
/** @var Queue $response */
$response = $cloudTasksClient->updateQueue($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
getLocation
Gets information about a location.
The async variant is CloudTasksClient::getLocationAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\Cloud\Location\Location |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function get_location_sample(): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = new GetLocationRequest();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $cloudTasksClient->getLocation($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
listLocations
Lists information about the supported locations for this service.
This method lists locations based on the resource scope provided in
the ListLocationsRequest.name field: *
Global locations: If name is empty, the method lists the
public locations available to all projects. * Project-specific
locations: If name follows the format
projects/{project}, the method lists locations visible to that
specific project. This includes public, private, or other
project-specific locations enabled for the project.
For gRPC and client library implementations, the resource name is
passed as the name field. For direct service calls, the resource
name is
incorporated into the request path based on the specific service
implementation and version.
The async variant is CloudTasksClient::listLocationsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 | |
|---|---|
| Type | Description |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function list_locations_sample(): void
{
// Create a client.
$cloudTasksClient = new CloudTasksClient();
// Prepare the request message.
$request = new ListLocationsRequest();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudTasksClient->listLocations($request);
/** @var Location $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
batchCreateTasksAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\BatchCreateTasksRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse> |
|
batchDeleteTasksAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\BatchDeleteTasksRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse> |
|
createQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\CreateQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Queue> |
|
createTaskAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\CreateTaskRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Task> |
|
deleteQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\DeleteQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<void> |
|
deleteTaskAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\DeleteTaskRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<void> |
|
getCmekConfigAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\GetCmekConfigRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\CmekConfig> |
|
getIamPolicyAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V1\GetIamPolicyRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Iam\V1\Policy> |
|
getQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\GetQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Queue> |
|
getTaskAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\GetTaskRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Task> |
|
listQueuesAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\ListQueuesRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
listTasksAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\ListTasksRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
pauseQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\PauseQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Queue> |
|
purgeQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\PurgeQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Queue> |
|
resumeQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\ResumeQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Queue> |
|
runTaskAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\RunTaskRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Task> |
|
setIamPolicyAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V1\SetIamPolicyRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Iam\V1\Policy> |
|
testIamPermissionsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V1\TestIamPermissionsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Iam\V1\TestIamPermissionsResponse> |
|
updateCmekConfigAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\UpdateCmekConfigRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\CmekConfig> |
|
updateQueueAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Tasks\V2\UpdateQueueRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Tasks\V2\Queue> |
|
getLocationAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Location\Location> |
|
listLocationsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
| Returns | |
|---|---|
| Type | Description |
Google\LongRunning\Client\OperationsClient |
|
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
| Parameters | |
|---|---|
| Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse |
|
static::cmekConfigName
Formats a string containing the fully-qualified path to represent a cmek_config resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted cmek_config resource. |
static::cryptoKeyName
Formats a string containing the fully-qualified path to represent a crypto_key resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
keyRing |
string
|
cryptoKey |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted crypto_key resource. |
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted location resource. |
static::queueName
Formats a string containing the fully-qualified path to represent a queue resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
queue |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted queue resource. |
static::taskName
Formats a string containing the fully-qualified path to represent a task resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
queue |
string
|
task |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The 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
- cmekConfig: projects/{project}/locations/{location}/cmekConfig
- cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}
- 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 | |
|---|---|
| Name | Description |
formattedName |
string
The formatted name string |
template |
?string
Optional name of template to match |
| Returns | |
|---|---|
| Type | Description |
array |
An associative array from name component IDs to component values. |