diff --git a/Tasks/src/V2/AppEngineHttpRequest.php b/Tasks/src/V2/AppEngineHttpRequest.php index f2cd2b1c1f0a..79bf879f8287 100644 --- a/Tasks/src/V2/AppEngineHttpRequest.php +++ b/Tasks/src/V2/AppEngineHttpRequest.php @@ -275,7 +275,7 @@ public function setHttpMethod($var) */ public function getAppEngineRouting() { - return isset($this->app_engine_routing) ? $this->app_engine_routing : null; + return $this->app_engine_routing; } public function hasAppEngineRouting() diff --git a/Tasks/src/V2/Attempt.php b/Tasks/src/V2/Attempt.php index dc986b297c17..279571f388db 100644 --- a/Tasks/src/V2/Attempt.php +++ b/Tasks/src/V2/Attempt.php @@ -80,7 +80,7 @@ public function __construct($data = NULL) { */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -118,7 +118,7 @@ public function setScheduleTime($var) */ public function getDispatchTime() { - return isset($this->dispatch_time) ? $this->dispatch_time : null; + return $this->dispatch_time; } public function hasDispatchTime() @@ -156,7 +156,7 @@ public function setDispatchTime($var) */ public function getResponseTime() { - return isset($this->response_time) ? $this->response_time : null; + return $this->response_time; } public function hasResponseTime() @@ -195,7 +195,7 @@ public function setResponseTime($var) */ public function getResponseStatus() { - return isset($this->response_status) ? $this->response_status : null; + return $this->response_status; } public function hasResponseStatus() diff --git a/Tasks/src/V2/CloudTasksClient.php b/Tasks/src/V2/CloudTasksClient.php index fd4fe6facb84..8dc621425f5c 100644 --- a/Tasks/src/V2/CloudTasksClient.php +++ b/Tasks/src/V2/CloudTasksClient.php @@ -17,20 +17,18 @@ /* * GENERATED CODE WARNING - * This file was generated from the file - * https://github.com/google/googleapis/blob/master/google/cloud/tasks/v2/cloudtasks.proto - * and updates to that file get reflected here through a refresh process. + * Generated by gapic-generator-php from the file + * https://github.com/googleapis/googleapis/blob/master/google/cloud/tasks/v2/cloudtasks.proto + * Updates to the above are reflected here through a refresh process. */ namespace Google\Cloud\Tasks\V2; use Google\Cloud\Tasks\V2\Gapic\CloudTasksGapicClient; -/** - * {@inheritdoc} - */ +/** {@inheritdoc} */ class CloudTasksClient extends CloudTasksGapicClient { - // This class is intentionally empty, and is intended to hold manual - // additions to the generated {@see CloudTasksGapicClient} class. + // This class is intentionally empty, and is intended to hold manual additions to + // the generated {@see CloudTasksGapicClient} class. } diff --git a/Tasks/src/V2/CreateQueueRequest.php b/Tasks/src/V2/CreateQueueRequest.php index 7742ab287d5e..246219ac0190 100644 --- a/Tasks/src/V2/CreateQueueRequest.php +++ b/Tasks/src/V2/CreateQueueRequest.php @@ -98,7 +98,7 @@ public function setParent($var) */ public function getQueue() { - return isset($this->queue) ? $this->queue : null; + return $this->queue; } public function hasQueue() diff --git a/Tasks/src/V2/CreateTaskRequest.php b/Tasks/src/V2/CreateTaskRequest.php index 1fb732cffb5c..55b13af87a22 100644 --- a/Tasks/src/V2/CreateTaskRequest.php +++ b/Tasks/src/V2/CreateTaskRequest.php @@ -194,7 +194,7 @@ public function setParent($var) */ public function getTask() { - return isset($this->task) ? $this->task : null; + return $this->task; } public function hasTask() diff --git a/Tasks/src/V2/Gapic/CloudTasksGapicClient.php b/Tasks/src/V2/Gapic/CloudTasksGapicClient.php index 29dd0ada6f47..1a7038f27d83 100644 --- a/Tasks/src/V2/Gapic/CloudTasksGapicClient.php +++ b/Tasks/src/V2/Gapic/CloudTasksGapicClient.php @@ -17,9 +17,9 @@ /* * GENERATED CODE WARNING - * This file was generated from the file - * https://github.com/google/googleapis/blob/master/google/cloud/tasks/v2/cloudtasks.proto - * and updates to that file get reflected here through a refresh process. + * Generated by gapic-generator-php from the file + * https://github.com/googleapis/googleapis/blob/master/google/cloud/tasks/v2/cloudtasks.proto + * Updates to the above are reflected here through a refresh process. */ namespace Google\Cloud\Tasks\V2\Gapic; @@ -27,6 +27,7 @@ use Google\ApiCore\ApiException; use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\GapicClientTrait; + use Google\ApiCore\PathTemplate; use Google\ApiCore\RequestParamsHeaderDescriptor; use Google\ApiCore\RetrySettings; @@ -71,31 +72,17 @@ * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * - * - * // Alternatively: - * - * // Iterate through all elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } + * $queue = new Queue(); + * $response = $cloudTasksClient->createQueue($formattedParent, $queue); * } finally { * $cloudTasksClient->close(); * } * ``` * - * 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. + * 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. */ class CloudTasksGapicClient { @@ -127,26 +114,29 @@ class CloudTasksGapicClient public static $serviceScopes = [ 'https://www.googleapis.com/auth/cloud-platform', ]; + private static $locationNameTemplate; - private static $projectNameTemplate; + private static $queueNameTemplate; + private static $taskNameTemplate; + private static $pathTemplateMap; private static function getClientDefaults() { return [ 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS.':'.self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__.'/../resources/cloud_tasks_client_config.json', - 'descriptorsConfigPath' => __DIR__.'/../resources/cloud_tasks_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__.'/../resources/cloud_tasks_grpc_config.json', + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/cloud_tasks_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/cloud_tasks_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/cloud_tasks_grpc_config.json', 'credentialsConfig' => [ 'defaultScopes' => self::$serviceScopes, ], 'transportConfig' => [ 'rest' => [ - 'restClientConfigPath' => __DIR__.'/../resources/cloud_tasks_rest_client_config.php', + 'restClientConfigPath' => __DIR__ . '/../resources/cloud_tasks_rest_client_config.php', ], ], ]; @@ -154,7 +144,7 @@ private static function getClientDefaults() private static function getLocationNameTemplate() { - if (null == self::$locationNameTemplate) { + if (self::$locationNameTemplate == null) { self::$locationNameTemplate = new PathTemplate('projects/{project}/locations/{location}'); } @@ -172,7 +162,7 @@ private static function getProjectNameTemplate() private static function getQueueNameTemplate() { - if (null == self::$queueNameTemplate) { + if (self::$queueNameTemplate == null) { self::$queueNameTemplate = new PathTemplate('projects/{project}/locations/{location}/queues/{queue}'); } @@ -181,7 +171,7 @@ private static function getQueueNameTemplate() private static function getTaskNameTemplate() { - if (null == self::$taskNameTemplate) { + if (self::$taskNameTemplate == null) { self::$taskNameTemplate = new PathTemplate('projects/{project}/locations/{location}/queues/{queue}/tasks/{task}'); } @@ -190,7 +180,7 @@ private static function getTaskNameTemplate() private static function getPathTemplateMap() { - if (null == self::$pathTemplateMap) { + if (self::$pathTemplateMap == null) { self::$pathTemplateMap = [ 'location' => self::getLocationNameTemplate(), 'project' => self::getProjectNameTemplate(), @@ -203,8 +193,8 @@ private static function getPathTemplateMap() } /** - * Formats a string containing the fully-qualified path to represent - * a location resource. + * Formats a string containing the fully-qualified path to represent a location + * resource. * * @param string $project * @param string $location @@ -220,8 +210,8 @@ public static function locationName($project, $location) } /** - * Formats a string containing the fully-qualified path to represent - * a queue resource. + * Formats a string containing the fully-qualified path to represent a queue + * resource. * * @param string $project * @param string $location @@ -239,8 +229,8 @@ public static function queueName($project, $location, $queue) } /** - * Formats a string containing the fully-qualified path to represent - * a task resource. + * Formats a string containing the fully-qualified path to represent a task + * resource. * * @param string $project * @param string $location @@ -280,12 +270,13 @@ public static function projectName($project) * Template: Pattern * - location: projects/{project}/locations/{location} * - queue: projects/{project}/locations/{location}/queues/{queue} - * - task: projects/{project}/locations/{location}/queues/{queue}/tasks/{task}. + * - 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. + * 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. * * @param string $formattedName The formatted name string * @param string $template Optional name of template to match @@ -297,7 +288,6 @@ public static function projectName($project) public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if ($template) { if (!isset($templateMap[$template])) { throw new ValidationException("Template name $template does not exist"); @@ -313,6 +303,7 @@ public static function parseName($formattedName, $template = null) // Swallow the exception to continue trying other path templates } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } @@ -320,7 +311,7 @@ public static function parseName($formattedName, $template = null) * Constructor. * * @param array $options { - * Optional. Options for configuring the service API wrapper. + * Optional. Options for configuring the service API wrapper. * * @type string $serviceAddress * **Deprecated**. This option will be removed in a future major release. Please @@ -337,35 +328,38 @@ public static function parseName($formattedName, $template = null) * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these * objects are provided, any settings in $credentialsConfig will be ignored. * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the client. - * For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()}. + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . * @type bool $disableRetries * Determines whether or not retries defined by the client configuration should be * disabled. Defaults to `false`. * @type string|array $clientConfig - * 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. + * 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. * @type string|TransportInterface $transport - * 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 - * {@see \Google\ApiCore\Transport\TransportInterface} object. Note that when this - * object is provided, any settings in $transportConfig, and any `$apiEndpoint` - * setting, will be ignored. + * 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 {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $serviceAddress setting, will be ignored. * @type array $transportConfig * 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' => [...] + * 'rest' => [...], * ]; * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the * supported options. + * @type callable $clientCertSource + * 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. * } * * @throws ValidationException @@ -376,153 +370,6 @@ public function __construct(array $options = []) $this->setClientOptions($clientOptions); } - /** - * Lists queues. - * - * Queues are returned in lexicographical order. - * - * Sample code: - * ``` - * $cloudTasksClient = new CloudTasksClient(); - * try { - * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * - * - * // Alternatively: - * - * // Iterate through all elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $cloudTasksClient->close(); - * } - * ``` - * - * @param string $parent Required. The location name. - * For example: `projects/PROJECT_ID/locations/LOCATION_ID` - * @param array $optionalArgs { - * Optional. - * - * @type string $filter - * `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2.Queue] - * field can be used as a filter and several operators as supported. - * For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as - * described in - * [Stackdriver's Advanced Logs - * Filters](https://cloud.google.com/logging/docs/view/advanced_filters). - * - * Sample filter "state: PAUSED". - * - * Note that using filters might cause fewer queues than the - * requested page_size to be returned. - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listQueues($parent, array $optionalArgs = []) - { - $request = new ListQueuesRequest(); - $request->setParent($parent); - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->getPagedListResponse( - 'ListQueues', - $optionalArgs, - ListQueuesResponse::class, - $request - ); - } - - /** - * Gets a queue. - * - * Sample code: - * ``` - * $cloudTasksClient = new CloudTasksClient(); - * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->getQueue($formattedName); - * } finally { - * $cloudTasksClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the queue. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Tasks\V2\Queue - * - * @throws ApiException if the remote call fails - */ - public function getQueue($name, array $optionalArgs = []) - { - $request = new GetQueueRequest(); - $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); - } - /** * Creates a queue. * @@ -549,23 +396,23 @@ public function getQueue($name, array $optionalArgs = []) * } * ``` * - * @param string $parent Required. The location name in which the queue will be created. - * For example: `projects/PROJECT_ID/locations/LOCATION_ID` + * @param string $parent Required. The location name in which the queue will be created. + * For example: `projects/PROJECT_ID/locations/LOCATION_ID` * - * The list of allowed locations can be obtained by calling Cloud - * Tasks' implementation of - * [ListLocations][google.cloud.location.Locations.ListLocations]. - * @param Queue $queue Required. The queue to create. + * The list of allowed locations can be obtained by calling Cloud + * Tasks' implementation of + * [ListLocations][google.cloud.location.Locations.ListLocations]. + * @param Queue $queue Required. The queue to create. * - * [Queue's name][google.cloud.tasks.v2.Queue.name] cannot be the same as an existing queue. - * @param array $optionalArgs { - * Optional. + * [Queue's name][google.cloud.tasks.v2.Queue.name] cannot be the same as an existing queue. + * @param array $optionalArgs { + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2\Queue @@ -575,98 +422,113 @@ public function getQueue($name, array $optionalArgs = []) public function createQueue($parent, $queue, array $optionalArgs = []) { $request = new CreateQueueRequest(); + $requestParamHeaders = []; $request->setParent($parent); $request->setQueue($queue); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CreateQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['parent'] = $parent; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CreateQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Updates a queue. - * - * This method creates the queue if it does not exist and updates - * the queue if it does exist. + * Creates a task and adds it to 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. + * Tasks cannot be updated after creation; there is no UpdateTask command. * - * WARNING: Using this method may have unintended side effects if you are - * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. - * Read - * [Overview of Queue Management and - * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using - * this method. + * * The maximum task size is 100KB. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $queue = new Queue(); - * $response = $cloudTasksClient->updateQueue($queue); + * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $task = new Task(); + * $response = $cloudTasksClient->createTask($formattedParent, $task); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param Queue $queue Required. The queue to create or update. - * - * The queue's [name][google.cloud.tasks.v2.Queue.name] must be specified. - * - * Output only fields cannot be modified using UpdateQueue. - * Any value specified for an output only field will be ignored. - * The queue's [name][google.cloud.tasks.v2.Queue.name] cannot be changed. - * @param array $optionalArgs { - * Optional. + * @param string $parent Required. The queue name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * - * @type FieldMask $updateMask - * A mask used to specify which fields of the queue are being updated. + * The queue must already exist. + * @param Task $task Required. The task to add. + * + * Task names have the following format: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. + * The user can optionally specify a task [name][google.cloud.tasks.v2.Task.name]. If a + * name is not specified then the system will generate a random + * unique task id, which will be set in the task returned in the + * [response][google.cloud.tasks.v2.Task.name]. + * + * If [schedule_time][google.cloud.tasks.v2.Task.schedule_time] is not set or is in the + * past then Cloud Tasks will set it to the current time. + * + * Task De-duplication: + * + * Explicitly specifying a task ID enables task de-duplication. If + * a task's ID is identical to that of an existing task or a task + * that was deleted or executed recently then the call will fail + * with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. + * If the task's queue was created using Cloud Tasks, then another task with + * the same name can't be created for ~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][google.cloud.tasks.v2.CloudTasks.CreateTask] calls have significantly + * increased latency. Using hashed strings for the task id or for + * the prefix of the task id is recommended. Choosing task ids that + * are sequential or have sequential prefixes, for example using a + * timestamp, causes an increase in latency and error rates in all + * task commands. The infrastructure relies on an approximately + * uniform distribution of task ids to store and serve tasks + * efficiently. + * @param array $optionalArgs { + * Optional. * - * If empty, then all fields will be updated. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2\Queue + * @return \Google\Cloud\Tasks\V2\Task * * @throws ApiException if the remote call fails */ - public function updateQueue($queue, array $optionalArgs = []) + public function createTask($parent, $task, array $optionalArgs = []) { - $request = new UpdateQueueRequest(); - $request->setQueue($queue); - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); + $request = new CreateTaskRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $request->setTask($task); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'queue.name' => $request->getQueue()->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'UpdateQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CreateTask', Task::class, $optionalArgs, $request)->wait(); } /** @@ -698,13 +560,13 @@ public function updateQueue($queue, array $optionalArgs = []) * @param string $name Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @throws ApiException if the remote call fails @@ -712,386 +574,299 @@ public function updateQueue($queue, array $optionalArgs = []) public function deleteQueue($name, array $optionalArgs = []) { $request = new DeleteQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'DeleteQueue', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteQueue', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Purges a queue by deleting all of its tasks. - * - * All tasks created before this method is called are permanently deleted. + * Deletes a task. * - * Purge operations can take up to one minute to take effect. Tasks - * might be dispatched before the purge takes effect. A purge is irreversible. + * 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: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->purgeQueue($formattedName); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $cloudTasksClient->deleteTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2\Queue - * * @throws ApiException if the remote call fails */ - public function purgeQueue($name, array $optionalArgs = []) + public function deleteTask($name, array $optionalArgs = []) { - $request = new PurgeQueueRequest(); + $request = new DeleteTaskRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'PurgeQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteTask', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Pauses the queue. + * Gets the access control policy for a [Queue][google.cloud.tasks.v2.Queue]. + * Returns an empty policy if the resource exists and does not have a policy + * set. * - * If a queue is paused then the system will stop dispatching tasks - * until the queue is resumed via - * [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. Tasks can still be added - * when the queue is paused. A queue is paused if its - * [state][google.cloud.tasks.v2.Queue.state] is [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED]. + * Authorization requires the following + * [Google IAM](https://cloud.google.com/iam) permission on the specified + * resource parent: + * + * * `cloudtasks.queues.getIamPolicy` * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->pauseQueue($formattedName); + * $resource = 'resource'; + * $response = $cloudTasksClient->getIamPolicy($resource); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $resource REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. * @param array $optionalArgs { - * Optional. + * Optional. * + * @type GetPolicyOptions $options + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2\Queue + * @return \Google\Cloud\Iam\V1\Policy * * @throws ApiException if the remote call fails */ - public function pauseQueue($name, array $optionalArgs = []) + public function getIamPolicy($resource, array $optionalArgs = []) { - $request = new PauseQueueRequest(); - $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); + $request = new GetIamPolicyRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $requestParamHeaders['resource'] = $resource; + if (isset($optionalArgs['options'])) { + $request->setOptions($optionalArgs['options']); + } - return $this->startCall( - 'PauseQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetIamPolicy', Policy::class, $optionalArgs, $request)->wait(); } /** - * Resume a queue. - * - * This method resumes a queue after it has been - * [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED] or - * [DISABLED][google.cloud.tasks.v2.Queue.State.DISABLED]. The state of a queue is stored - * in the queue's [state][google.cloud.tasks.v2.Queue.state]; after calling this method it - * will be set to [RUNNING][google.cloud.tasks.v2.Queue.State.RUNNING]. - * - * WARNING: Resuming many high-QPS queues at the same time can - * lead to target overloading. If you are resuming high-QPS - * queues, follow the 500/50/5 pattern described in - * [Managing Cloud Tasks Scaling - * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). + * Gets a queue. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->resumeQueue($formattedName); + * $response = $cloudTasksClient->getQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $name Required. The resource name of the queue. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2\Queue * * @throws ApiException if the remote call fails */ - public function resumeQueue($name, array $optionalArgs = []) + public function getQueue($name, array $optionalArgs = []) { - $request = new ResumeQueueRequest(); + $request = new GetQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'ResumeQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Gets the access control policy for a [Queue][google.cloud.tasks.v2.Queue]. - * Returns an empty policy if the resource exists and does not have a policy - * set. - * - * Authorization requires the following - * [Google IAM](https://cloud.google.com/iam) permission on the specified - * resource parent: - * - * * `cloudtasks.queues.getIamPolicy` + * Gets a task. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $response = $cloudTasksClient->getIamPolicy($resource); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $response = $cloudTasksClient->getTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $resource REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * - * @type GetPolicyOptions $options - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. This field is only used by Cloud IAM. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\Policy + * @return \Google\Cloud\Tasks\V2\Task * * @throws ApiException if the remote call fails */ - public function getIamPolicy($resource, array $optionalArgs = []) + public function getTask($name, array $optionalArgs = []) { - $request = new GetIamPolicyRequest(); - $request->setResource($resource); - if (isset($optionalArgs['options'])) { - $request->setOptions($optionalArgs['options']); + $request = new GetTaskRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetIamPolicy', - Policy::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetTask', Task::class, $optionalArgs, $request)->wait(); } /** - * Sets the access control policy for a [Queue][google.cloud.tasks.v2.Queue]. Replaces any existing - * policy. - * - * Note: The Cloud Console does not check queue-level IAM permissions yet. - * Project-level permissions are required to use the Cloud Console. - * - * Authorization requires the following - * [Google IAM](https://cloud.google.com/iam) permission on the specified - * resource parent: + * Lists queues. * - * * `cloudtasks.queues.setIamPolicy` + * Queues are returned in lexicographical order. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $policy = new Policy(); - * $response = $cloudTasksClient->setIamPolicy($resource, $policy); + * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); + * // Iterate over pages of elements + * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $resource REQUIRED: The resource for which the policy is being specified. - * See the operation documentation for the appropriate value for this field. - * @param Policy $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. + * @param string $parent Required. The location name. + * For example: `projects/PROJECT_ID/locations/LOCATION_ID` * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Iam\V1\Policy + * Optional. * - * @throws ApiException if the remote call fails - */ - public function setIamPolicy($resource, $policy, array $optionalArgs = []) - { - $request = new SetIamPolicyRequest(); - $request->setResource($resource); - $request->setPolicy($policy); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'SetIamPolicy', - Policy::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2.Queue]. - * If the resource does not exist, this will return an empty set of - * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. - * - * Note: This operation is designed to be used for building permission-aware - * UIs and command-line tools, not for authorization checking. This operation - * may "fail open" without warning. - * - * Sample code: - * ``` - * $cloudTasksClient = new CloudTasksClient(); - * try { - * $resource = ''; - * $permissions = []; - * $response = $cloudTasksClient->testIamPermissions($resource, $permissions); - * } finally { - * $cloudTasksClient->close(); - * } - * ``` + * @type string $filter + * `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2.Queue] + * field can be used as a filter and several operators as supported. + * For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as + * described in + * [Stackdriver's Advanced Logs + * Filters](https://cloud.google.com/logging/docs/view/advanced_filters). * - * @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[] $permissions The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see - * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). - * @param array $optionalArgs { - * Optional. + * Sample filter "state: PAUSED". * + * Note that using filters might cause fewer queues than the + * requested page_size to be returned. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse + * @return \Google\ApiCore\PagedListResponse * * @throws ApiException if the remote call fails */ - public function testIamPermissions($resource, $permissions, array $optionalArgs = []) + public function listQueues($parent, array $optionalArgs = []) { - $request = new TestIamPermissionsRequest(); - $request->setResource($resource); - $request->setPermissions($permissions); + $request = new ListQueuesRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } - return $this->startCall( - 'TestIamPermissions', - TestIamPermissionsResponse::class, - $optionalArgs, - $request - )->wait(); + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListQueues', $optionalArgs, ListQueuesResponse::class, $request); } /** @@ -1117,10 +892,7 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs * // doSomethingWith($element); * } * } - * - * * // Alternatively: - * * // Iterate through all elements * $pagedResponse = $cloudTasksClient->listTasks($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -1134,36 +906,36 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs * @param string $parent Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\ApiCore\PagedListResponse @@ -1173,257 +945,170 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs public function listTasks($parent, array $optionalArgs = []) { $request = new ListTasksRequest(); + $requestParamHeaders = []; $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; if (isset($optionalArgs['responseView'])) { $request->setResponseView($optionalArgs['responseView']); } + if (isset($optionalArgs['pageSize'])) { $request->setPageSize($optionalArgs['pageSize']); } + if (isset($optionalArgs['pageToken'])) { $request->setPageToken($optionalArgs['pageToken']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->getPagedListResponse( - 'ListTasks', - $optionalArgs, - ListTasksResponse::class, - $request - ); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListTasks', $optionalArgs, ListTasksResponse::class, $request); } /** - * Gets a task. + * Pauses the queue. + * + * If a queue is paused then the system will stop dispatching tasks + * until the queue is resumed via + * [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. Tasks can still be added + * when the queue is paused. A queue is paused if its + * [state][google.cloud.tasks.v2.Queue.state] is [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $response = $cloudTasksClient->getTask($formattedName); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->pauseQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2\Task + * @return \Google\Cloud\Tasks\V2\Queue * * @throws ApiException if the remote call fails */ - public function getTask($name, array $optionalArgs = []) + public function pauseQueue($name, array $optionalArgs = []) { - $request = new GetTaskRequest(); + $request = new PauseQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PauseQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Creates a task and adds it to a queue. + * Purges a queue by deleting all of its tasks. * - * Tasks cannot be updated after creation; there is no UpdateTask command. + * All tasks created before this method is called are permanently deleted. * - * * The maximum task size is 100KB. + * 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: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $task = new Task(); - * $response = $cloudTasksClient->createTask($formattedParent, $task); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->purgeQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $parent Required. The queue name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * - * The queue must already exist. - * @param Task $task Required. The task to add. - * - * Task names have the following format: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. - * The user can optionally specify a task [name][google.cloud.tasks.v2.Task.name]. If a - * name is not specified then the system will generate a random - * unique task id, which will be set in the task returned in the - * [response][google.cloud.tasks.v2.Task.name]. - * - * If [schedule_time][google.cloud.tasks.v2.Task.schedule_time] is not set or is in the - * past then Cloud Tasks will set it to the current time. - * - * Task De-duplication: - * - * Explicitly specifying a task ID enables task de-duplication. If - * a task's ID is identical to that of an existing task or a task - * that was deleted or executed recently then the call will fail - * with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. - * If the task's queue was created using Cloud Tasks, then another task with - * the same name can't be created for ~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][google.cloud.tasks.v2.CloudTasks.CreateTask] calls have significantly - * increased latency. Using hashed strings for the task id or for - * the prefix of the task id is recommended. Choosing task ids that - * are sequential or have sequential prefixes, for example using a - * timestamp, causes an increase in latency and error rates in all - * task commands. The infrastructure relies on an approximately - * uniform distribution of task ids to store and serve tasks - * efficiently. - * @param array $optionalArgs { - * Optional. + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param array $optionalArgs { + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2\Task + * @return \Google\Cloud\Tasks\V2\Queue * * @throws ApiException if the remote call fails */ - public function createTask($parent, $task, array $optionalArgs = []) + public function purgeQueue($name, array $optionalArgs = []) { - $request = new CreateTaskRequest(); - $request->setParent($parent); - $request->setTask($task); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CreateTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $request = new PurgeQueueRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PurgeQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Deletes a task. + * Resume a queue. * - * A task can be deleted if it is scheduled or dispatched. A task - * cannot be deleted if it has executed successfully or permanently - * failed. + * This method resumes a queue after it has been + * [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED] or + * [DISABLED][google.cloud.tasks.v2.Queue.State.DISABLED]. The state of a queue is stored + * in the queue's [state][google.cloud.tasks.v2.Queue.state]; after calling this method it + * will be set to [RUNNING][google.cloud.tasks.v2.Queue.State.RUNNING]. + * + * WARNING: Resuming many high-QPS queues at the same time can + * lead to target overloading. If you are resuming high-QPS + * queues, follow the 500/50/5 pattern described in + * [Managing Cloud Tasks Scaling + * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $cloudTasksClient->deleteTask($formattedName); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->resumeQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * + * @return \Google\Cloud\Tasks\V2\Queue + * * @throws ApiException if the remote call fails */ - public function deleteTask($name, array $optionalArgs = []) + public function resumeQueue($name, array $optionalArgs = []) { - $request = new DeleteTaskRequest(); + $request = new ResumeQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'DeleteTask', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('ResumeQueue', Queue::class, $optionalArgs, $request)->wait(); } /** @@ -1466,27 +1151,27 @@ public function deleteTask($name, array $optionalArgs = []) * @param string $name Required. The task name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2\Task @@ -1496,23 +1181,193 @@ public function deleteTask($name, array $optionalArgs = []) public function runTask($name, array $optionalArgs = []) { $request = new RunTaskRequest(); + $requestParamHeaders = []; $request->setName($name); + $requestParamHeaders['name'] = $name; if (isset($optionalArgs['responseView'])) { $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('RunTask', Task::class, $optionalArgs, $request)->wait(); + } + + /** + * Sets the access control policy for a [Queue][google.cloud.tasks.v2.Queue]. Replaces any existing + * policy. + * + * Note: The Cloud Console does not check queue-level IAM permissions yet. + * Project-level permissions are required to use the Cloud Console. + * + * Authorization requires the following + * [Google IAM](https://cloud.google.com/iam) permission on the specified + * resource parent: + * + * * `cloudtasks.queues.setIamPolicy` + * + * Sample code: + * ``` + * $cloudTasksClient = new CloudTasksClient(); + * try { + * $resource = 'resource'; + * $policy = new Policy(); + * $response = $cloudTasksClient->setIamPolicy($resource, $policy); + * } finally { + * $cloudTasksClient->close(); + * } + * ``` + * + * @param string $resource REQUIRED: The resource for which the policy is being specified. + * See the operation documentation for the appropriate value for this field. + * @param Policy $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. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Iam\V1\Policy + * + * @throws ApiException if the remote call fails + */ + public function setIamPolicy($resource, $policy, array $optionalArgs = []) + { + $request = new SetIamPolicyRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $request->setPolicy($policy); + $requestParamHeaders['resource'] = $resource; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('SetIamPolicy', Policy::class, $optionalArgs, $request)->wait(); + } + + /** + * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2.Queue]. + * If the resource does not exist, this will return an empty set of + * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. + * + * Note: This operation is designed to be used for building permission-aware + * UIs and command-line tools, not for authorization checking. This operation + * may "fail open" without warning. + * + * Sample code: + * ``` + * $cloudTasksClient = new CloudTasksClient(); + * try { + * $resource = 'resource'; + * $permissions = []; + * $response = $cloudTasksClient->testIamPermissions($resource, $permissions); + * } finally { + * $cloudTasksClient->close(); + * } + * ``` + * + * @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[] $permissions The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse + * + * @throws ApiException if the remote call fails + */ + public function testIamPermissions($resource, $permissions, array $optionalArgs = []) + { + $request = new TestIamPermissionsRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $request->setPermissions($permissions); + $requestParamHeaders['resource'] = $resource; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('TestIamPermissions', TestIamPermissionsResponse::class, $optionalArgs, $request)->wait(); + } + + /** + * Updates a queue. + * + * This method creates the queue if it does not exist and updates + * the queue if it does exist. + * + * Queues created with this method allow tasks to live for a maximum of 31 + * days. After a task is 31 days old, the task will be deleted regardless of whether + * it was dispatched or not. + * + * WARNING: Using this method may have unintended side effects if you are + * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. + * Read + * [Overview of Queue Management and + * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using + * this method. + * + * Sample code: + * ``` + * $cloudTasksClient = new CloudTasksClient(); + * try { + * $queue = new Queue(); + * $response = $cloudTasksClient->updateQueue($queue); + * } finally { + * $cloudTasksClient->close(); + * } + * ``` + * + * @param Queue $queue Required. The queue to create or update. + * + * The queue's [name][google.cloud.tasks.v2.Queue.name] must be specified. + * + * Output only fields cannot be modified using UpdateQueue. + * Any value specified for an output only field will be ignored. + * The queue's [name][google.cloud.tasks.v2.Queue.name] cannot be changed. + * @param array $optionalArgs { + * Optional. + * + * @type FieldMask $updateMask + * A mask used to specify which fields of the queue are being updated. + * + * If empty, then all fields will be updated. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Tasks\V2\Queue + * + * @throws ApiException if the remote call fails + */ + public function updateQueue($queue, array $optionalArgs = []) + { + $request = new UpdateQueueRequest(); + $requestParamHeaders = []; + $request->setQueue($queue); + $requestParamHeaders['queue.name'] = $queue->getName(); + if (isset($optionalArgs['updateMask'])) { + $request->setUpdateMask($optionalArgs['updateMask']); + } - return $this->startCall( - 'RunTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('UpdateQueue', Queue::class, $optionalArgs, $request)->wait(); } } diff --git a/Tasks/src/V2/HttpRequest.php b/Tasks/src/V2/HttpRequest.php index 5a77f6288f21..8dabbc2d03f9 100644 --- a/Tasks/src/V2/HttpRequest.php +++ b/Tasks/src/V2/HttpRequest.php @@ -66,8 +66,8 @@ class HttpRequest extends \Google\Protobuf\Internal\Message * [HttpRequest.url][google.cloud.tasks.v2.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. @@ -119,8 +119,8 @@ class HttpRequest extends \Google\Protobuf\Internal\Message * [HttpRequest.url][google.cloud.tasks.v2.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. @@ -232,8 +232,8 @@ public function setHttpMethod($var) * [HttpRequest.url][google.cloud.tasks.v2.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. @@ -263,8 +263,8 @@ public function getHeaders() * [HttpRequest.url][google.cloud.tasks.v2.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. diff --git a/Tasks/src/V2/Queue.php b/Tasks/src/V2/Queue.php index cdef419f62c8..46f68ed0a7e5 100644 --- a/Tasks/src/V2/Queue.php +++ b/Tasks/src/V2/Queue.php @@ -287,7 +287,7 @@ public function setName($var) */ public function getAppEngineRoutingOverride() { - return isset($this->app_engine_routing_override) ? $this->app_engine_routing_override : null; + return $this->app_engine_routing_override; } public function hasAppEngineRoutingOverride() @@ -350,7 +350,7 @@ public function setAppEngineRoutingOverride($var) */ public function getRateLimits() { - return isset($this->rate_limits) ? $this->rate_limits : null; + return $this->rate_limits; } public function hasRateLimits() @@ -413,7 +413,7 @@ public function setRateLimits($var) */ public function getRetryConfig() { - return isset($this->retry_config) ? $this->retry_config : null; + return $this->retry_config; } public function hasRetryConfig() @@ -500,7 +500,7 @@ public function setState($var) */ public function getPurgeTime() { - return isset($this->purge_time) ? $this->purge_time : null; + return $this->purge_time; } public function hasPurgeTime() @@ -545,7 +545,7 @@ public function setPurgeTime($var) */ public function getStackdriverLoggingConfig() { - return isset($this->stackdriver_logging_config) ? $this->stackdriver_logging_config : null; + return $this->stackdriver_logging_config; } public function hasStackdriverLoggingConfig() diff --git a/Tasks/src/V2/RetryConfig.php b/Tasks/src/V2/RetryConfig.php index 325eaa0f2b90..2b1083d1c897 100644 --- a/Tasks/src/V2/RetryConfig.php +++ b/Tasks/src/V2/RetryConfig.php @@ -256,7 +256,7 @@ public function setMaxAttempts($var) */ public function getMaxRetryDuration() { - return isset($this->max_retry_duration) ? $this->max_retry_duration : null; + return $this->max_retry_duration; } public function hasMaxRetryDuration() @@ -314,7 +314,7 @@ public function setMaxRetryDuration($var) */ public function getMinBackoff() { - return isset($this->min_backoff) ? $this->min_backoff : null; + return $this->min_backoff; } public function hasMinBackoff() @@ -370,7 +370,7 @@ public function setMinBackoff($var) */ public function getMaxBackoff() { - return isset($this->max_backoff) ? $this->max_backoff : null; + return $this->max_backoff; } public function hasMaxBackoff() diff --git a/Tasks/src/V2/Task.php b/Tasks/src/V2/Task.php index 5c9ce9d6388e..72bf25e135a2 100644 --- a/Tasks/src/V2/Task.php +++ b/Tasks/src/V2/Task.php @@ -337,7 +337,7 @@ public function setHttpRequest($var) */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -375,7 +375,7 @@ public function setScheduleTime($var) */ public function getCreateTime() { - return isset($this->create_time) ? $this->create_time : null; + return $this->create_time; } public function hasCreateTime() @@ -437,7 +437,7 @@ public function setCreateTime($var) */ public function getDispatchDeadline() { - return isset($this->dispatch_deadline) ? $this->dispatch_deadline : null; + return $this->dispatch_deadline; } public function hasDispatchDeadline() @@ -556,7 +556,7 @@ public function setResponseCount($var) */ public function getFirstAttempt() { - return isset($this->first_attempt) ? $this->first_attempt : null; + return $this->first_attempt; } public function hasFirstAttempt() @@ -594,7 +594,7 @@ public function setFirstAttempt($var) */ public function getLastAttempt() { - return isset($this->last_attempt) ? $this->last_attempt : null; + return $this->last_attempt; } public function hasLastAttempt() diff --git a/Tasks/src/V2/UpdateQueueRequest.php b/Tasks/src/V2/UpdateQueueRequest.php index fdd95102e7c2..106f4b67243d 100644 --- a/Tasks/src/V2/UpdateQueueRequest.php +++ b/Tasks/src/V2/UpdateQueueRequest.php @@ -67,7 +67,7 @@ public function __construct($data = NULL) { */ public function getQueue() { - return isset($this->queue) ? $this->queue : null; + return $this->queue; } public function hasQueue() @@ -108,7 +108,7 @@ public function setQueue($var) */ public function getUpdateMask() { - return isset($this->update_mask) ? $this->update_mask : null; + return $this->update_mask; } public function hasUpdateMask() diff --git a/Tasks/src/V2/gapic_metadata.json b/Tasks/src/V2/gapic_metadata.json new file mode 100644 index 000000000000..6277d0594d0f --- /dev/null +++ b/Tasks/src/V2/gapic_metadata.json @@ -0,0 +1,98 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services\/RPCs to the corresponding library clients\/methods", + "language": "php", + "protoPackage": "google.cloud.tasks.v2", + "libraryPackage": "Google\\Cloud\\Tasks\\V2", + "services": { + "CloudTasks": { + "clients": { + "grpc": { + "libraryClient": "CloudTasksGapicClient", + "rpcs": { + "CreateQueue": { + "methods": [ + "createQueue" + ] + }, + "CreateTask": { + "methods": [ + "createTask" + ] + }, + "DeleteQueue": { + "methods": [ + "deleteQueue" + ] + }, + "DeleteTask": { + "methods": [ + "deleteTask" + ] + }, + "GetIamPolicy": { + "methods": [ + "getIamPolicy" + ] + }, + "GetQueue": { + "methods": [ + "getQueue" + ] + }, + "GetTask": { + "methods": [ + "getTask" + ] + }, + "ListQueues": { + "methods": [ + "listQueues" + ] + }, + "ListTasks": { + "methods": [ + "listTasks" + ] + }, + "PauseQueue": { + "methods": [ + "pauseQueue" + ] + }, + "PurgeQueue": { + "methods": [ + "purgeQueue" + ] + }, + "ResumeQueue": { + "methods": [ + "resumeQueue" + ] + }, + "RunTask": { + "methods": [ + "runTask" + ] + }, + "SetIamPolicy": { + "methods": [ + "setIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "testIamPermissions" + ] + }, + "UpdateQueue": { + "methods": [ + "updateQueue" + ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Tasks/src/V2/resources/cloud_tasks_client_config.json b/Tasks/src/V2/resources/cloud_tasks_client_config.json index fd96fd3a8747..4bae73ae12b6 100644 --- a/Tasks/src/V2/resources/cloud_tasks_client_config.json +++ b/Tasks/src/V2/resources/cloud_tasks_client_config.json @@ -1,125 +1,125 @@ { - "interfaces": { - "google.cloud.tasks.v2.CloudTasks": { - "retry_codes": { - "retry_policy_1_codes": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "no_retry_codes": [], - "no_retry_1_codes": [] - }, - "retry_params": { - "retry_policy_1_params": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 10000, - "initial_rpc_timeout_millis": 10000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 10000, - "total_timeout_millis": 10000 - }, - "no_retry_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 0, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 0, - "total_timeout_millis": 0 - }, - "no_retry_1_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 10000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 10000, - "total_timeout_millis": 10000 + "interfaces": { + "google.cloud.tasks.v2.CloudTasks": { + "retry_codes": { + "no_retry_codes": [], + "retry_policy_1_codes": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "no_retry_1_codes": [] + }, + "retry_params": { + "no_retry_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 0, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 0, + "total_timeout_millis": 0 + }, + "retry_policy_1_params": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 10000, + "initial_rpc_timeout_millis": 10000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 10000, + "total_timeout_millis": 10000 + }, + "no_retry_1_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 10000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 10000, + "total_timeout_millis": 10000 + } + }, + "methods": { + "CreateQueue": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "CreateTask": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "DeleteQueue": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "DeleteTask": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetIamPolicy": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetQueue": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetTask": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListQueues": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListTasks": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "PauseQueue": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "PurgeQueue": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "ResumeQueue": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "RunTask": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "SetIamPolicy": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "TestIamPermissions": { + "timeout_millis": 10000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "UpdateQueue": { + "timeout_millis": 10000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + } + } } - }, - "methods": { - "ListQueues": { - "timeout_millis": 15000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "GetQueue": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "CreateQueue": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "UpdateQueue": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "DeleteQueue": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "PurgeQueue": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "PauseQueue": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "ResumeQueue": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "GetIamPolicy": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "SetIamPolicy": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "TestIamPermissions": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "ListTasks": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "GetTask": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "CreateTask": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "DeleteTask": { - "timeout_millis": 10000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "RunTask": { - "timeout_millis": 10000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - } - } } - } } diff --git a/Tasks/src/V2/resources/cloud_tasks_rest_client_config.php b/Tasks/src/V2/resources/cloud_tasks_rest_client_config.php index 5f9e4deca013..5f0644a0be9d 100644 --- a/Tasks/src/V2/resources/cloud_tasks_rest_client_config.php +++ b/Tasks/src/V2/resources/cloud_tasks_rest_client_config.php @@ -3,9 +3,10 @@ return [ 'interfaces' => [ 'google.cloud.tasks.v2.CloudTasks' => [ - 'ListQueues' => [ - 'method' => 'get', + 'CreateQueue' => [ + 'method' => 'post', 'uriTemplate' => '/v2/{parent=projects/*/locations/*}/queues', + 'body' => 'queue', 'placeholders' => [ 'parent' => [ 'getters' => [ @@ -14,21 +15,10 @@ ], ], ], - 'GetQueue' => [ - 'method' => 'get', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], - 'CreateQueue' => [ + 'CreateTask' => [ 'method' => 'post', - 'uriTemplate' => '/v2/{parent=projects/*/locations/*}/queues', - 'body' => 'queue', + 'uriTemplate' => '/v2/{parent=projects/*/locations/*/queues/*}/tasks', + 'body' => '*', 'placeholders' => [ 'parent' => [ 'getters' => [ @@ -37,22 +27,20 @@ ], ], ], - 'UpdateQueue' => [ - 'method' => 'patch', - 'uriTemplate' => '/v2/{queue.name=projects/*/locations/*/queues/*}', - 'body' => 'queue', + 'DeleteQueue' => [ + 'method' => 'delete', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}', 'placeholders' => [ - 'queue.name' => [ + 'name' => [ 'getters' => [ - 'getQueue', 'getName', ], ], ], ], - 'DeleteQueue' => [ + 'DeleteTask' => [ 'method' => 'delete', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*/tasks/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -61,22 +49,21 @@ ], ], ], - 'PurgeQueue' => [ + 'GetIamPolicy' => [ 'method' => 'post', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}:purge', + 'uriTemplate' => '/v2/{resource=projects/*/locations/*/queues/*}:getIamPolicy', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'PauseQueue' => [ - 'method' => 'post', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}:pause', - 'body' => '*', + 'GetQueue' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -85,10 +72,9 @@ ], ], ], - 'ResumeQueue' => [ - 'method' => 'post', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}:resume', - 'body' => '*', + 'GetTask' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*/tasks/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -97,56 +83,56 @@ ], ], ], - 'GetIamPolicy' => [ - 'method' => 'post', - 'uriTemplate' => '/v2/{resource=projects/*/locations/*/queues/*}:getIamPolicy', - 'body' => '*', + 'ListQueues' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{parent=projects/*/locations/*}/queues', 'placeholders' => [ - 'resource' => [ + 'parent' => [ 'getters' => [ - 'getResource', + 'getParent', ], ], ], ], - 'SetIamPolicy' => [ - 'method' => 'post', - 'uriTemplate' => '/v2/{resource=projects/*/locations/*/queues/*}:setIamPolicy', - 'body' => '*', + 'ListTasks' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{parent=projects/*/locations/*/queues/*}/tasks', 'placeholders' => [ - 'resource' => [ + 'parent' => [ 'getters' => [ - 'getResource', + 'getParent', ], ], ], ], - 'TestIamPermissions' => [ + 'PauseQueue' => [ 'method' => 'post', - 'uriTemplate' => '/v2/{resource=projects/*/locations/*/queues/*}:testIamPermissions', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}:pause', 'body' => '*', 'placeholders' => [ - 'resource' => [ + 'name' => [ 'getters' => [ - 'getResource', + 'getName', ], ], ], ], - 'ListTasks' => [ - 'method' => 'get', - 'uriTemplate' => '/v2/{parent=projects/*/locations/*/queues/*}/tasks', + 'PurgeQueue' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}:purge', + 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'GetTask' => [ - 'method' => 'get', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*/tasks/*}', + 'ResumeQueue' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*}:resume', + 'body' => '*', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -155,36 +141,50 @@ ], ], ], - 'CreateTask' => [ + 'RunTask' => [ 'method' => 'post', - 'uriTemplate' => '/v2/{parent=projects/*/locations/*/queues/*}/tasks', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*/tasks/*}:run', 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'DeleteTask' => [ - 'method' => 'delete', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*/tasks/*}', + 'SetIamPolicy' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{resource=projects/*/locations/*/queues/*}:setIamPolicy', + 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'RunTask' => [ + 'TestIamPermissions' => [ 'method' => 'post', - 'uriTemplate' => '/v2/{name=projects/*/locations/*/queues/*/tasks/*}:run', + 'uriTemplate' => '/v2/{resource=projects/*/locations/*/queues/*}:testIamPermissions', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ + 'getters' => [ + 'getResource', + ], + ], + ], + ], + 'UpdateQueue' => [ + 'method' => 'patch', + 'uriTemplate' => '/v2/{queue.name=projects/*/locations/*/queues/*}', + 'body' => 'queue', + 'placeholders' => [ + 'queue.name' => [ 'getters' => [ + 'getQueue', 'getName', ], ], diff --git a/Tasks/src/V2beta2/AcknowledgeTaskRequest.php b/Tasks/src/V2beta2/AcknowledgeTaskRequest.php index c07c703e9439..249894669f4c 100644 --- a/Tasks/src/V2beta2/AcknowledgeTaskRequest.php +++ b/Tasks/src/V2beta2/AcknowledgeTaskRequest.php @@ -96,7 +96,7 @@ public function setName($var) */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() diff --git a/Tasks/src/V2beta2/AppEngineHttpRequest.php b/Tasks/src/V2beta2/AppEngineHttpRequest.php index 0ed11ac87d26..b7a5020d0e91 100644 --- a/Tasks/src/V2beta2/AppEngineHttpRequest.php +++ b/Tasks/src/V2beta2/AppEngineHttpRequest.php @@ -270,7 +270,7 @@ public function setHttpMethod($var) */ public function getAppEngineRouting() { - return isset($this->app_engine_routing) ? $this->app_engine_routing : null; + return $this->app_engine_routing; } public function hasAppEngineRouting() diff --git a/Tasks/src/V2beta2/AppEngineHttpTarget.php b/Tasks/src/V2beta2/AppEngineHttpTarget.php index bdae54cd604f..d5f8a6871ae7 100644 --- a/Tasks/src/V2beta2/AppEngineHttpTarget.php +++ b/Tasks/src/V2beta2/AppEngineHttpTarget.php @@ -66,7 +66,7 @@ public function __construct($data = NULL) { */ public function getAppEngineRoutingOverride() { - return isset($this->app_engine_routing_override) ? $this->app_engine_routing_override : null; + return $this->app_engine_routing_override; } public function hasAppEngineRoutingOverride() diff --git a/Tasks/src/V2beta2/AttemptStatus.php b/Tasks/src/V2beta2/AttemptStatus.php index a814038ef196..b8a349382bb4 100644 --- a/Tasks/src/V2beta2/AttemptStatus.php +++ b/Tasks/src/V2beta2/AttemptStatus.php @@ -80,7 +80,7 @@ public function __construct($data = NULL) { */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -118,7 +118,7 @@ public function setScheduleTime($var) */ public function getDispatchTime() { - return isset($this->dispatch_time) ? $this->dispatch_time : null; + return $this->dispatch_time; } public function hasDispatchTime() @@ -156,7 +156,7 @@ public function setDispatchTime($var) */ public function getResponseTime() { - return isset($this->response_time) ? $this->response_time : null; + return $this->response_time; } public function hasResponseTime() @@ -195,7 +195,7 @@ public function setResponseTime($var) */ public function getResponseStatus() { - return isset($this->response_status) ? $this->response_status : null; + return $this->response_status; } public function hasResponseStatus() diff --git a/Tasks/src/V2beta2/CancelLeaseRequest.php b/Tasks/src/V2beta2/CancelLeaseRequest.php index 9f401d27b1b1..9b6a2e3d4494 100644 --- a/Tasks/src/V2beta2/CancelLeaseRequest.php +++ b/Tasks/src/V2beta2/CancelLeaseRequest.php @@ -122,7 +122,7 @@ public function setName($var) */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() diff --git a/Tasks/src/V2beta2/CloudTasksClient.php b/Tasks/src/V2beta2/CloudTasksClient.php index f9131aca22ba..0559226dcc38 100644 --- a/Tasks/src/V2beta2/CloudTasksClient.php +++ b/Tasks/src/V2beta2/CloudTasksClient.php @@ -17,9 +17,9 @@ /* * GENERATED CODE WARNING - * This file was generated from the file - * https://github.com/google/googleapis/blob/master/google/cloud/tasks/v2beta2/cloudtasks.proto - * and updates to that file get reflected here through a refresh process. + * Generated by gapic-generator-php from the file + * https://github.com/googleapis/googleapis/blob/master/google/cloud/tasks/v2beta2/cloudtasks.proto + * Updates to the above are reflected here through a refresh process. * * @experimental */ @@ -28,11 +28,9 @@ use Google\Cloud\Tasks\V2beta2\Gapic\CloudTasksGapicClient; -/** - * {@inheritdoc} - */ +/** {@inheritdoc} */ class CloudTasksClient extends CloudTasksGapicClient { - // This class is intentionally empty, and is intended to hold manual - // additions to the generated {@see CloudTasksGapicClient} class. + // This class is intentionally empty, and is intended to hold manual additions to + // the generated {@see CloudTasksGapicClient} class. } diff --git a/Tasks/src/V2beta2/CreateQueueRequest.php b/Tasks/src/V2beta2/CreateQueueRequest.php index 6b93ba215f83..d5b049bb2cac 100644 --- a/Tasks/src/V2beta2/CreateQueueRequest.php +++ b/Tasks/src/V2beta2/CreateQueueRequest.php @@ -98,7 +98,7 @@ public function setParent($var) */ public function getQueue() { - return isset($this->queue) ? $this->queue : null; + return $this->queue; } public function hasQueue() diff --git a/Tasks/src/V2beta2/CreateTaskRequest.php b/Tasks/src/V2beta2/CreateTaskRequest.php index 57f17bc6b803..08f3b2ddd8f5 100644 --- a/Tasks/src/V2beta2/CreateTaskRequest.php +++ b/Tasks/src/V2beta2/CreateTaskRequest.php @@ -194,7 +194,7 @@ public function setParent($var) */ public function getTask() { - return isset($this->task) ? $this->task : null; + return $this->task; } public function hasTask() diff --git a/Tasks/src/V2beta2/Gapic/CloudTasksGapicClient.php b/Tasks/src/V2beta2/Gapic/CloudTasksGapicClient.php index 4fefba83238b..004279589178 100644 --- a/Tasks/src/V2beta2/Gapic/CloudTasksGapicClient.php +++ b/Tasks/src/V2beta2/Gapic/CloudTasksGapicClient.php @@ -17,9 +17,9 @@ /* * GENERATED CODE WARNING - * This file was generated from the file - * https://github.com/google/googleapis/blob/master/google/cloud/tasks/v2beta2/cloudtasks.proto - * and updates to that file get reflected here through a refresh process. + * Generated by gapic-generator-php from the file + * https://github.com/googleapis/googleapis/blob/master/google/cloud/tasks/v2beta2/cloudtasks.proto + * Updates to the above are reflected here through a refresh process. * * @experimental */ @@ -29,6 +29,7 @@ use Google\ApiCore\ApiException; use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\GapicClientTrait; + use Google\ApiCore\PathTemplate; use Google\ApiCore\RequestParamsHeaderDescriptor; use Google\ApiCore\RetrySettings; @@ -79,32 +80,18 @@ * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * - * - * // Alternatively: - * - * // Iterate through all elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $scheduleTime = new Timestamp(); + * $cloudTasksClient->acknowledgeTask($formattedName, $scheduleTime); * } finally { * $cloudTasksClient->close(); * } * ``` * - * 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. + * 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. * * @experimental */ @@ -138,26 +125,29 @@ class CloudTasksGapicClient public static $serviceScopes = [ 'https://www.googleapis.com/auth/cloud-platform', ]; + private static $locationNameTemplate; - private static $projectNameTemplate; + private static $queueNameTemplate; + private static $taskNameTemplate; + private static $pathTemplateMap; private static function getClientDefaults() { return [ 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS.':'.self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__.'/../resources/cloud_tasks_client_config.json', - 'descriptorsConfigPath' => __DIR__.'/../resources/cloud_tasks_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__.'/../resources/cloud_tasks_grpc_config.json', + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/cloud_tasks_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/cloud_tasks_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/cloud_tasks_grpc_config.json', 'credentialsConfig' => [ 'defaultScopes' => self::$serviceScopes, ], 'transportConfig' => [ 'rest' => [ - 'restClientConfigPath' => __DIR__.'/../resources/cloud_tasks_rest_client_config.php', + 'restClientConfigPath' => __DIR__ . '/../resources/cloud_tasks_rest_client_config.php', ], ], ]; @@ -165,7 +155,7 @@ private static function getClientDefaults() private static function getLocationNameTemplate() { - if (null == self::$locationNameTemplate) { + if (self::$locationNameTemplate == null) { self::$locationNameTemplate = new PathTemplate('projects/{project}/locations/{location}'); } @@ -183,7 +173,7 @@ private static function getProjectNameTemplate() private static function getQueueNameTemplate() { - if (null == self::$queueNameTemplate) { + if (self::$queueNameTemplate == null) { self::$queueNameTemplate = new PathTemplate('projects/{project}/locations/{location}/queues/{queue}'); } @@ -192,7 +182,7 @@ private static function getQueueNameTemplate() private static function getTaskNameTemplate() { - if (null == self::$taskNameTemplate) { + if (self::$taskNameTemplate == null) { self::$taskNameTemplate = new PathTemplate('projects/{project}/locations/{location}/queues/{queue}/tasks/{task}'); } @@ -201,7 +191,7 @@ private static function getTaskNameTemplate() private static function getPathTemplateMap() { - if (null == self::$pathTemplateMap) { + if (self::$pathTemplateMap == null) { self::$pathTemplateMap = [ 'location' => self::getLocationNameTemplate(), 'project' => self::getProjectNameTemplate(), @@ -214,13 +204,14 @@ private static function getPathTemplateMap() } /** - * Formats a string containing the fully-qualified path to represent - * a location resource. + * Formats a string containing the fully-qualified path to represent a location + * resource. * * @param string $project * @param string $location * * @return string The formatted location resource. + * * @experimental */ public static function locationName($project, $location) @@ -232,14 +223,15 @@ public static function locationName($project, $location) } /** - * Formats a string containing the fully-qualified path to represent - * a queue resource. + * Formats a string containing the fully-qualified path to represent a queue + * resource. * * @param string $project * @param string $location * @param string $queue * * @return string The formatted queue resource. + * * @experimental */ public static function queueName($project, $location, $queue) @@ -252,8 +244,8 @@ public static function queueName($project, $location, $queue) } /** - * Formats a string containing the fully-qualified path to represent - * a task resource. + * Formats a string containing the fully-qualified path to represent a task + * resource. * * @param string $project * @param string $location @@ -261,6 +253,7 @@ public static function queueName($project, $location, $queue) * @param string $task * * @return string The formatted task resource. + * * @experimental */ public static function taskName($project, $location, $queue, $task) @@ -294,12 +287,13 @@ public static function projectName($project) * Template: Pattern * - location: projects/{project}/locations/{location} * - queue: projects/{project}/locations/{location}/queues/{queue} - * - task: projects/{project}/locations/{location}/queues/{queue}/tasks/{task}. + * - 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. + * 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. * * @param string $formattedName The formatted name string * @param string $template Optional name of template to match @@ -307,12 +301,12 @@ public static function projectName($project) * @return array An associative array from name component IDs to component values. * * @throws ValidationException If $formattedName could not be matched. + * * @experimental */ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if ($template) { if (!isset($templateMap[$template])) { throw new ValidationException("Template name $template does not exist"); @@ -328,6 +322,7 @@ public static function parseName($formattedName, $template = null) // Swallow the exception to continue trying other path templates } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } @@ -335,7 +330,7 @@ public static function parseName($formattedName, $template = null) * Constructor. * * @param array $options { - * Optional. Options for configuring the service API wrapper. + * Optional. Options for configuring the service API wrapper. * * @type string $serviceAddress * **Deprecated**. This option will be removed in a future major release. Please @@ -352,38 +347,42 @@ public static function parseName($formattedName, $template = null) * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these * objects are provided, any settings in $credentialsConfig will be ignored. * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the client. - * For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()}. + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . * @type bool $disableRetries * Determines whether or not retries defined by the client configuration should be * disabled. Defaults to `false`. * @type string|array $clientConfig - * 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. + * 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. * @type string|TransportInterface $transport - * 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 - * {@see \Google\ApiCore\Transport\TransportInterface} object. Note that when this - * object is provided, any settings in $transportConfig, and any `$apiEndpoint` - * setting, will be ignored. + * 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 {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $serviceAddress setting, will be ignored. * @type array $transportConfig * 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' => [...] + * 'rest' => [...], * ]; * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the * supported options. + * @type callable $clientCertSource + * 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. * } * * @throws ValidationException + * * @experimental */ public function __construct(array $options = []) @@ -393,168 +392,136 @@ public function __construct(array $options = []) } /** - * Lists queues. + * Acknowledges a pull task. * - * Queues are returned in lexicographical order. + * The worker, that is, the entity that + * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method + * to indicate that the work associated with the task has finished. + * + * The worker must acknowledge a task within the + * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease + * will expire and the task will become available to be leased + * again. After the task is acknowledged, it will not be returned + * by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], + * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or + * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * - * - * // Alternatively: - * - * // Iterate through all elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $scheduleTime = new Timestamp(); + * $cloudTasksClient->acknowledgeTask($formattedName, $scheduleTime); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $parent Required. The location name. - * For example: `projects/PROJECT_ID/locations/LOCATION_ID` - * @param array $optionalArgs { - * Optional. - * - * @type string $filter - * `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2beta2.Queue] - * field can be used as a filter and several operators as supported. - * For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as - * described in - * [Stackdriver's Advanced Logs - * Filters](https://cloud.google.com/logging/docs/view/advanced_filters). - * - * Sample filter "app_engine_http_target: *". + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param Timestamp $scheduleTime Required. The task's current schedule time, available in the + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by + * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or + * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is + * to ensure that your worker currently holds the lease. + * @param array $optionalArgs { + * Optional. * - * Note that using filters might cause fewer queues than the - * requested_page size to be returned. - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type FieldMask $readMask - * Optional. Read mask is used for a more granular control over what the API returns. - * If the mask is not present all fields will be returned except - * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly - * specified in the mask. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\ApiCore\PagedListResponse - * * @throws ApiException if the remote call fails + * * @experimental */ - public function listQueues($parent, array $optionalArgs = []) + public function acknowledgeTask($name, $scheduleTime, array $optionalArgs = []) { - $request = new ListQueuesRequest(); - $request->setParent($parent); - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - if (isset($optionalArgs['readMask'])) { - $request->setReadMask($optionalArgs['readMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->getPagedListResponse( - 'ListQueues', - $optionalArgs, - ListQueuesResponse::class, - $request - ); + $request = new AcknowledgeTaskRequest(); + $requestParamHeaders = []; + $request->setName($name); + $request->setScheduleTime($scheduleTime); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('AcknowledgeTask', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Gets a queue. + * Cancel a pull task's lease. + * + * The worker can use this method to cancel a task's lease by + * setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will + * make the task available to be leased to the next caller of + * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->getQueue($formattedName); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $scheduleTime = new Timestamp(); + * $response = $cloudTasksClient->cancelLease($formattedName, $scheduleTime); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The resource name of the queue. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * @param array $optionalArgs { - * Optional. + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param Timestamp $scheduleTime Required. The task's current schedule time, available in the + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by + * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or + * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is + * to ensure that your worker currently holds the lease. + * @param array $optionalArgs { + * Optional. * - * @type FieldMask $readMask - * Optional. Read mask is used for a more granular control over what the API returns. - * If the mask is not present all fields will be returned except - * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly - * specified in the mask. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Queue + * @return \Google\Cloud\Tasks\V2beta2\Task * * @throws ApiException if the remote call fails + * * @experimental */ - public function getQueue($name, array $optionalArgs = []) + public function cancelLease($name, $scheduleTime, array $optionalArgs = []) { - $request = new GetQueueRequest(); + $request = new CancelLeaseRequest(); + $requestParamHeaders = []; $request->setName($name); - if (isset($optionalArgs['readMask'])) { - $request->setReadMask($optionalArgs['readMask']); + $request->setScheduleTime($scheduleTime); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CancelLease', Task::class, $optionalArgs, $request)->wait(); } /** @@ -583,126 +550,145 @@ public function getQueue($name, array $optionalArgs = []) * } * ``` * - * @param string $parent Required. The location name in which the queue will be created. - * For example: `projects/PROJECT_ID/locations/LOCATION_ID` + * @param string $parent Required. The location name in which the queue will be created. + * For example: `projects/PROJECT_ID/locations/LOCATION_ID` * - * The list of allowed locations can be obtained by calling Cloud - * Tasks' implementation of - * [ListLocations][google.cloud.location.Locations.ListLocations]. - * @param Queue $queue Required. The queue to create. + * The list of allowed locations can be obtained by calling Cloud + * Tasks' implementation of + * [ListLocations][google.cloud.location.Locations.ListLocations]. + * @param Queue $queue Required. The queue to create. * - * [Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing queue. - * @param array $optionalArgs { - * Optional. + * [Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing queue. + * @param array $optionalArgs { + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2beta2\Queue * * @throws ApiException if the remote call fails + * * @experimental */ public function createQueue($parent, $queue, array $optionalArgs = []) { $request = new CreateQueueRequest(); + $requestParamHeaders = []; $request->setParent($parent); $request->setQueue($queue); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CreateQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['parent'] = $parent; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CreateQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Updates a queue. - * - * This method creates the queue if it does not exist and updates - * the queue if it does exist. + * Creates a task and adds it to 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. + * Tasks cannot be updated after creation; there is no UpdateTask command. * - * WARNING: Using this method may have unintended side effects if you are - * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. - * Read - * [Overview of Queue Management and - * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using - * this method. + * * For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is + * 100KB. + * * For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $queue = new Queue(); - * $response = $cloudTasksClient->updateQueue($queue); + * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $task = new Task(); + * $response = $cloudTasksClient->createTask($formattedParent, $task); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param Queue $queue Required. The queue to create or update. - * - * The queue's [name][google.cloud.tasks.v2beta2.Queue.name] must be specified. - * - * Output only fields cannot be modified using UpdateQueue. - * Any value specified for an output only field will be ignored. - * The queue's [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed. - * @param array $optionalArgs { - * Optional. + * @param string $parent Required. The queue name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * - * @type FieldMask $updateMask - * A mask used to specify which fields of the queue are being updated. + * The queue must already exist. + * @param Task $task Required. The task to add. + * + * Task names have the following format: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. + * The user can optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a + * name is not specified then the system will generate a random + * unique task id, which will be set in the task returned in the + * [response][google.cloud.tasks.v2beta2.Task.name]. + * + * If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in the + * past then Cloud Tasks will set it to the current time. + * + * Task De-duplication: + * + * Explicitly specifying a task ID enables task de-duplication. If + * a task's ID is identical to that of an existing task or a task + * that was deleted or completed recently then the call will fail + * with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. + * If the task's queue was created using Cloud Tasks, then another task with + * the same name can't be created for ~1hour after the original task was + * deleted or completed. If the task's queue was created using queue.yaml or + * queue.xml, then another task with the same name can't be created + * for ~9days after the original task was deleted or completed. + * + * Because there is an extra lookup cost to identify duplicate task + * names, these [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly + * increased latency. Using hashed strings for the task id or for + * the prefix of the task id is recommended. Choosing task ids that + * are sequential or have sequential prefixes, for example using a + * timestamp, causes an increase in latency and error rates in all + * task commands. The infrastructure relies on an approximately + * uniform distribution of task ids to store and serve tasks + * efficiently. + * @param array $optionalArgs { + * Optional. * - * If empty, then all fields will be updated. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Queue + * @return \Google\Cloud\Tasks\V2beta2\Task * * @throws ApiException if the remote call fails + * * @experimental */ - public function updateQueue($queue, array $optionalArgs = []) + public function createTask($parent, $task, array $optionalArgs = []) { - $request = new UpdateQueueRequest(); - $request->setQueue($queue); - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); + $request = new CreateTaskRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $request->setTask($task); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'queue.name' => $request->getQueue()->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'UpdateQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CreateTask', Task::class, $optionalArgs, $request)->wait(); } /** @@ -734,407 +720,495 @@ public function updateQueue($queue, array $optionalArgs = []) * @param string $name Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @throws ApiException if the remote call fails + * * @experimental */ public function deleteQueue($name, array $optionalArgs = []) { $request = new DeleteQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'DeleteQueue', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteQueue', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Purges a queue by deleting all of its tasks. - * - * All tasks created before this method is called are permanently deleted. + * Deletes a task. * - * Purge operations can take up to one minute to take effect. Tasks - * might be dispatched before the purge takes effect. A purge is irreversible. + * A task can be deleted if it is scheduled or dispatched. A task + * cannot be deleted if it has completed successfully or permanently + * failed. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->purgeQueue($formattedName); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $cloudTasksClient->deleteTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Queue - * * @throws ApiException if the remote call fails + * * @experimental */ - public function purgeQueue($name, array $optionalArgs = []) + public function deleteTask($name, array $optionalArgs = []) { - $request = new PurgeQueueRequest(); + $request = new DeleteTaskRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'PurgeQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteTask', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Pauses the queue. + * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. + * Returns an empty policy if the resource exists and does not have a policy + * set. * - * If a queue is paused then the system will stop dispatching tasks - * until the queue is resumed via - * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added - * when the queue is paused. A queue is paused if its - * [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. + * Authorization requires the following + * [Google IAM](https://cloud.google.com/iam) permission on the specified + * resource parent: + * + * * `cloudtasks.queues.getIamPolicy` * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->pauseQueue($formattedName); + * $resource = 'resource'; + * $response = $cloudTasksClient->getIamPolicy($resource); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $resource REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. * @param array $optionalArgs { - * Optional. + * Optional. * + * @type GetPolicyOptions $options + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Queue + * @return \Google\Cloud\Iam\V1\Policy * * @throws ApiException if the remote call fails + * * @experimental */ - public function pauseQueue($name, array $optionalArgs = []) + public function getIamPolicy($resource, array $optionalArgs = []) { - $request = new PauseQueueRequest(); - $request->setName($name); + $request = new GetIamPolicyRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $requestParamHeaders['resource'] = $resource; + if (isset($optionalArgs['options'])) { + $request->setOptions($optionalArgs['options']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'PauseQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetIamPolicy', Policy::class, $optionalArgs, $request)->wait(); } /** - * Resume a queue. - * - * This method resumes a queue after it has been - * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or - * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored - * in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it - * will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING]. - * - * WARNING: Resuming many high-QPS queues at the same time can - * lead to target overloading. If you are resuming high-QPS - * queues, follow the 500/50/5 pattern described in - * [Managing Cloud Tasks Scaling - * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). + * Gets a queue. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->resumeQueue($formattedName); + * $response = $cloudTasksClient->getQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $name Required. The resource name of the queue. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * + * @type FieldMask $readMask + * Optional. Read mask is used for a more granular control over what the API returns. + * If the mask is not present all fields will be returned except + * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + * specified in the mask. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2beta2\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function resumeQueue($name, array $optionalArgs = []) + public function getQueue($name, array $optionalArgs = []) { - $request = new ResumeQueueRequest(); + $request = new GetQueueRequest(); + $requestParamHeaders = []; $request->setName($name); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['readMask'])) { + $request->setReadMask($optionalArgs['readMask']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'ResumeQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. - * Returns an empty policy if the resource exists and does not have a policy - * set. - * - * Authorization requires the following - * [Google IAM](https://cloud.google.com/iam) permission on the specified - * resource parent: - * - * * `cloudtasks.queues.getIamPolicy` + * Gets a task. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $response = $cloudTasksClient->getIamPolicy($resource); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $response = $cloudTasksClient->getTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $resource REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * - * @type GetPolicyOptions $options - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. This field is only used by Cloud IAM. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\Policy + * @return \Google\Cloud\Tasks\V2beta2\Task * * @throws ApiException if the remote call fails + * * @experimental */ - public function getIamPolicy($resource, array $optionalArgs = []) + public function getTask($name, array $optionalArgs = []) { - $request = new GetIamPolicyRequest(); - $request->setResource($resource); - if (isset($optionalArgs['options'])) { - $request->setOptions($optionalArgs['options']); + $request = new GetTaskRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetIamPolicy', - Policy::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetTask', Task::class, $optionalArgs, $request)->wait(); } /** - * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing - * policy. + * Leases tasks from a pull queue for + * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration]. * - * Note: The Cloud Console does not check queue-level IAM permissions yet. - * Project-level permissions are required to use the Cloud Console. + * This method is invoked by the worker to obtain a lease. The + * worker must acknowledge the task via + * [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have + * performed the work associated with the task. * - * Authorization requires the following - * [Google IAM](https://cloud.google.com/iam) permission on the specified - * resource parent: + * The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that + * the worker needs to perform the work associated with the task. To + * return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set + * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to + * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL]. * - * * `cloudtasks.queues.setIamPolicy` + * A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] + * requests are allowed per + * queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] + * is returned when this limit is + * exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] + * is also returned when + * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] + * is exceeded. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $policy = new Policy(); - * $response = $cloudTasksClient->setIamPolicy($resource, $policy); + * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $leaseDuration = new Duration(); + * $response = $cloudTasksClient->leaseTasks($formattedParent, $leaseDuration); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $resource REQUIRED: The resource for which the policy is being specified. - * See the operation documentation for the appropriate value for this field. - * @param Policy $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. - * @param array $optionalArgs { - * Optional. + * @param string $parent Required. The queue name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` + * @param Duration $leaseDuration Required. The duration of the lease. + * + * Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will + * have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current + * time plus the `lease_duration`. The task is leased until its + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be + * returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call + * before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. * + * + * After the worker has successfully finished the work associated + * with the task, the worker must call via + * [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] before the + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Otherwise the task will be + * returned to a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call so + * that another worker can retry it. + * + * The maximum lease duration is 1 week. + * `lease_duration` will be truncated to the nearest second. + * @param array $optionalArgs { + * Optional. + * + * @type int $maxTasks + * The maximum number of tasks to lease. + * + * The system will make a best effort to return as close to as + * `max_tasks` as possible. + * + * The largest that `max_tasks` can be is 1000. + * + * The maximum total size of a [lease tasks response][google.cloud.tasks.v2beta2.LeaseTasksResponse] is + * 32 MB. If the sum of all task sizes requested reaches this limit, + * fewer tasks than requested are returned. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} + * @type string $filter + * `filter` can be used to specify a subset of tasks to lease. + * + * When `filter` is set to `tag=` then the + * [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will contain only tasks whose + * [tag][google.cloud.tasks.v2beta2.PullMessage.tag] is equal to ``. `` must be + * less than 500 characters. + * + * When `filter` is set to `tag_function=oldest_tag()`, only tasks which have + * the same tag as the task with the oldest + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be returned. + * + * Grammar Syntax: + * + * * `filter = "tag=" tag | "tag_function=" function` + * + * * `tag = string` + * + * * `function = "oldest_tag()"` + * + * The `oldest_tag()` function returns tasks which have the same tag as the + * oldest task (ordered by schedule time). + * + * SDK compatibility: Although the SDK allows tags to be either + * string or + * [bytes](https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/TaskOptions.html#tag-byte:A-), + * only UTF-8 encoded tags can be used in Cloud Tasks. Tag which + * aren't UTF-8 encoded can't be used in the + * [filter][google.cloud.tasks.v2beta2.LeaseTasksRequest.filter] and the task's + * [tag][google.cloud.tasks.v2beta2.PullMessage.tag] will be displayed as empty in Cloud Tasks. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\Policy + * @return \Google\Cloud\Tasks\V2beta2\LeaseTasksResponse * * @throws ApiException if the remote call fails + * * @experimental */ - public function setIamPolicy($resource, $policy, array $optionalArgs = []) + public function leaseTasks($parent, $leaseDuration, array $optionalArgs = []) { - $request = new SetIamPolicyRequest(); - $request->setResource($resource); - $request->setPolicy($policy); + $request = new LeaseTasksRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $request->setLeaseDuration($leaseDuration); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['maxTasks'])) { + $request->setMaxTasks($optionalArgs['maxTasks']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'SetIamPolicy', - Policy::class, - $optionalArgs, - $request - )->wait(); + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); + } + + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('LeaseTasks', LeaseTasksResponse::class, $optionalArgs, $request)->wait(); } /** - * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. - * If the resource does not exist, this will return an empty set of - * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. + * Lists queues. * - * 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. + * Queues are returned in lexicographical order. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $permissions = []; - * $response = $cloudTasksClient->testIamPermissions($resource, $permissions); + * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); + * // Iterate over pages of elements + * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } * } finally { * $cloudTasksClient->close(); * } * ``` * - * @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[] $permissions The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see - * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). - * @param array $optionalArgs { - * Optional. + * @param string $parent Required. The location name. + * For example: `projects/PROJECT_ID/locations/LOCATION_ID` + * @param array $optionalArgs { + * Optional. + * + * @type string $filter + * `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2beta2.Queue] + * field can be used as a filter and several operators as supported. + * For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as + * described in + * [Stackdriver's Advanced Logs + * Filters](https://cloud.google.com/logging/docs/view/advanced_filters). * + * Sample filter "app_engine_http_target: *". + * + * Note that using filters might cause fewer queues than the + * requested_page size to be returned. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type FieldMask $readMask + * Optional. Read mask is used for a more granular control over what the API returns. + * If the mask is not present all fields will be returned except + * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + * specified in the mask. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse + * @return \Google\ApiCore\PagedListResponse * * @throws ApiException if the remote call fails + * * @experimental */ - public function testIamPermissions($resource, $permissions, array $optionalArgs = []) + public function listQueues($parent, array $optionalArgs = []) { - $request = new TestIamPermissionsRequest(); - $request->setResource($resource); - $request->setPermissions($permissions); + $request = new ListQueuesRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'TestIamPermissions', - TestIamPermissionsResponse::class, - $optionalArgs, - $request - )->wait(); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + if (isset($optionalArgs['readMask'])) { + $request->setReadMask($optionalArgs['readMask']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListQueues', $optionalArgs, ListQueuesResponse::class, $request); } /** @@ -1160,10 +1234,7 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs * // doSomethingWith($element); * } * } - * - * * // Alternatively: - * * // Iterate through all elements * $pagedResponse = $cloudTasksClient->listTasks($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -1177,771 +1248,566 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs * @param string $parent Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\ApiCore\PagedListResponse * * @throws ApiException if the remote call fails + * * @experimental */ public function listTasks($parent, array $optionalArgs = []) { $request = new ListTasksRequest(); + $requestParamHeaders = []; $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; if (isset($optionalArgs['responseView'])) { $request->setResponseView($optionalArgs['responseView']); } + if (isset($optionalArgs['pageSize'])) { $request->setPageSize($optionalArgs['pageSize']); } + if (isset($optionalArgs['pageToken'])) { $request->setPageToken($optionalArgs['pageToken']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->getPagedListResponse( - 'ListTasks', - $optionalArgs, - ListTasksResponse::class, - $request - ); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListTasks', $optionalArgs, ListTasksResponse::class, $request); } /** - * Gets a task. + * Pauses the queue. + * + * If a queue is paused then the system will stop dispatching tasks + * until the queue is resumed via + * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added + * when the queue is paused. A queue is paused if its + * [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $response = $cloudTasksClient->getTask($formattedName); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->pauseQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Task + * @return \Google\Cloud\Tasks\V2beta2\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function getTask($name, array $optionalArgs = []) + public function pauseQueue($name, array $optionalArgs = []) { - $request = new GetTaskRequest(); + $request = new PauseQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PauseQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Creates a task and adds it to a queue. + * Purges a queue by deleting all of its tasks. * - * Tasks cannot be updated after creation; there is no UpdateTask command. + * All tasks created before this method is called are permanently deleted. * - * * For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is - * 100KB. - * * For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB. + * 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: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $task = new Task(); - * $response = $cloudTasksClient->createTask($formattedParent, $task); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->purgeQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $parent Required. The queue name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * - * The queue must already exist. - * @param Task $task Required. The task to add. - * - * Task names have the following format: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. - * The user can optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a - * name is not specified then the system will generate a random - * unique task id, which will be set in the task returned in the - * [response][google.cloud.tasks.v2beta2.Task.name]. - * - * If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in the - * past then Cloud Tasks will set it to the current time. - * - * Task De-duplication: - * - * Explicitly specifying a task ID enables task de-duplication. If - * a task's ID is identical to that of an existing task or a task - * that was deleted or completed recently then the call will fail - * with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. - * If the task's queue was created using Cloud Tasks, then another task with - * the same name can't be created for ~1hour after the original task was - * deleted or completed. If the task's queue was created using queue.yaml or - * queue.xml, then another task with the same name can't be created - * for ~9days after the original task was deleted or completed. - * - * Because there is an extra lookup cost to identify duplicate task - * names, these [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly - * increased latency. Using hashed strings for the task id or for - * the prefix of the task id is recommended. Choosing task ids that - * are sequential or have sequential prefixes, for example using a - * timestamp, causes an increase in latency and error rates in all - * task commands. The infrastructure relies on an approximately - * uniform distribution of task ids to store and serve tasks - * efficiently. - * @param array $optionalArgs { - * Optional. + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param array $optionalArgs { + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Task + * @return \Google\Cloud\Tasks\V2beta2\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function createTask($parent, $task, array $optionalArgs = []) + public function purgeQueue($name, array $optionalArgs = []) { - $request = new CreateTaskRequest(); - $request->setParent($parent); - $request->setTask($task); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CreateTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $request = new PurgeQueueRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PurgeQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Deletes a task. + * Renew the current lease of a pull task. * - * A task can be deleted if it is scheduled or dispatched. A task - * cannot be deleted if it has completed successfully or permanently - * failed. + * The worker can use this method to extend the lease by a new + * duration, starting from now. The new task lease will be + * returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $cloudTasksClient->deleteTask($formattedName); + * $scheduleTime = new Timestamp(); + * $leaseDuration = new Duration(); + * $response = $cloudTasksClient->renewLease($formattedName, $scheduleTime, $leaseDuration); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` - * @param array $optionalArgs { - * Optional. + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param Timestamp $scheduleTime Required. The task's current schedule time, available in the + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by + * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or + * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is + * to ensure that your worker currently holds the lease. + * @param Duration $leaseDuration Required. The desired new lease duration, starting from now. + * + * + * The maximum lease duration is 1 week. + * `lease_duration` will be truncated to the nearest second. + * @param array $optionalArgs { + * Optional. * + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * + * @return \Google\Cloud\Tasks\V2beta2\Task + * * @throws ApiException if the remote call fails + * * @experimental */ - public function deleteTask($name, array $optionalArgs = []) + public function renewLease($name, $scheduleTime, $leaseDuration, array $optionalArgs = []) { - $request = new DeleteTaskRequest(); + $request = new RenewLeaseRequest(); + $requestParamHeaders = []; $request->setName($name); + $request->setScheduleTime($scheduleTime); + $request->setLeaseDuration($leaseDuration); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'DeleteTask', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('RenewLease', Task::class, $optionalArgs, $request)->wait(); } /** - * Leases tasks from a pull queue for - * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration]. - * - * This method is invoked by the worker to obtain a lease. The - * worker must acknowledge the task via - * [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have - * performed the work associated with the task. + * Resume a queue. * - * The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that - * the worker needs to perform the work associated with the task. To - * return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set - * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to - * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL]. + * This method resumes a queue after it has been + * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or + * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored + * in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it + * will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING]. * - * A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] - * requests are allowed per - * queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] - * is returned when this limit is - * exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] - * is also returned when - * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] - * is exceeded. + * WARNING: Resuming many high-QPS queues at the same time can + * lead to target overloading. If you are resuming high-QPS + * queues, follow the 500/50/5 pattern described in + * [Managing Cloud Tasks Scaling + * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $leaseDuration = new Duration(); - * $response = $cloudTasksClient->leaseTasks($formattedParent, $leaseDuration); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->resumeQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $parent Required. The queue name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * @param Duration $leaseDuration Required. The duration of the lease. - * - * Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will - * have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current - * time plus the `lease_duration`. The task is leased until its - * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be - * returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call - * before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. - * @param array $optionalArgs { - * Optional. - * - * @type int $maxTasks - * The maximum number of tasks to lease. - * - * The system will make a best effort to return as close to as - * `max_tasks` as possible. - * - * The largest that `max_tasks` can be is 1000. - * - * The maximum total size of a [lease tasks response][google.cloud.tasks.v2beta2.LeaseTasksResponse] is - * 32 MB. If the sum of all task sizes requested reaches this limit, - * fewer tasks than requested are returned. - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} - * @type string $filter - * `filter` can be used to specify a subset of tasks to lease. - * - * When `filter` is set to `tag=` then the - * [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will contain only tasks whose - * [tag][google.cloud.tasks.v2beta2.PullMessage.tag] is equal to ``. `` must be - * less than 500 characters. - * - * When `filter` is set to `tag_function=oldest_tag()`, only tasks which have - * the same tag as the task with the oldest - * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be returned. - * - * Grammar Syntax: - * - * * `filter = "tag=" tag | "tag_function=" function` - * - * * `tag = string` - * - * * `function = "oldest_tag()"` - * - * The `oldest_tag()` function returns tasks which have the same tag as the - * oldest task (ordered by schedule time). + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param array $optionalArgs { + * Optional. * - * SDK compatibility: Although the SDK allows tags to be either - * string or - * [bytes](https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/TaskOptions.html#tag-byte:A-), - * only UTF-8 encoded tags can be used in Cloud Tasks. Tag which - * aren't UTF-8 encoded can't be used in the - * [filter][google.cloud.tasks.v2beta2.LeaseTasksRequest.filter] and the task's - * [tag][google.cloud.tasks.v2beta2.PullMessage.tag] will be displayed as empty in Cloud Tasks. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\LeaseTasksResponse + * @return \Google\Cloud\Tasks\V2beta2\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function leaseTasks($parent, $leaseDuration, array $optionalArgs = []) + public function resumeQueue($name, array $optionalArgs = []) { - $request = new LeaseTasksRequest(); - $request->setParent($parent); - $request->setLeaseDuration($leaseDuration); - if (isset($optionalArgs['maxTasks'])) { - $request->setMaxTasks($optionalArgs['maxTasks']); - } - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'LeaseTasks', - LeaseTasksResponse::class, - $optionalArgs, - $request - )->wait(); + $request = new ResumeQueueRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('ResumeQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Acknowledges a pull task. + * Forces a task to run now. * - * The worker, that is, the entity that - * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method - * to indicate that the work associated with the task has finished. + * When this method is called, Cloud Tasks will dispatch the task, even if + * the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or + * is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. * - * The worker must acknowledge a task within the - * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease - * will expire and the task will become available to be leased - * again. After the task is acknowledged, it will not be returned - * by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], - * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or - * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. + * This command is meant to be used for manual debugging. For + * example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed + * task after a fix has been made or to manually force a task to be + * dispatched now. + * + * The dispatched task is returned. That is, the task that is returned + * contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but + * before the task is received by its target. + * + * If Cloud Tasks receives a successful response from the task's + * target, then the task will be deleted; otherwise the task's + * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that + * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified + * in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig]. + * + * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns + * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a + * task that has already succeeded or permanently failed. + * + * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a + * [pull task][google.cloud.tasks.v2beta2.PullMessage]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $scheduleTime = new Timestamp(); - * $cloudTasksClient->acknowledgeTask($formattedName, $scheduleTime); + * $response = $cloudTasksClient->runTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` - * @param Timestamp $scheduleTime Required. The task's current schedule time, available in the - * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by - * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or - * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is - * to ensure that your worker currently holds the lease. - * @param array $optionalArgs { - * Optional. + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param array $optionalArgs { + * Optional. * + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * + * @return \Google\Cloud\Tasks\V2beta2\Task + * * @throws ApiException if the remote call fails + * * @experimental */ - public function acknowledgeTask($name, $scheduleTime, array $optionalArgs = []) + public function runTask($name, array $optionalArgs = []) { - $request = new AcknowledgeTaskRequest(); + $request = new RunTaskRequest(); + $requestParamHeaders = []; $request->setName($name); - $request->setScheduleTime($scheduleTime); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'AcknowledgeTask', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('RunTask', Task::class, $optionalArgs, $request)->wait(); } /** - * Renew the current lease of a pull task. + * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing + * policy. * - * The worker can use this method to extend the lease by a new - * duration, starting from now. The new task lease will be - * returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. + * Note: The Cloud Console does not check queue-level IAM permissions yet. + * Project-level permissions are required to use the Cloud Console. + * + * Authorization requires the following + * [Google IAM](https://cloud.google.com/iam) permission on the specified + * resource parent: + * + * * `cloudtasks.queues.setIamPolicy` * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $scheduleTime = new Timestamp(); - * $leaseDuration = new Duration(); - * $response = $cloudTasksClient->renewLease($formattedName, $scheduleTime, $leaseDuration); + * $resource = 'resource'; + * $policy = new Policy(); + * $response = $cloudTasksClient->setIamPolicy($resource, $policy); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` - * @param Timestamp $scheduleTime Required. The task's current schedule time, available in the - * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by - * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or - * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is - * to ensure that your worker currently holds the lease. - * @param Duration $leaseDuration Required. The desired new lease duration, starting from now. - * @param array $optionalArgs { - * Optional. + * @param string $resource REQUIRED: The resource for which the policy is being specified. + * See the operation documentation for the appropriate value for this field. + * @param Policy $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. + * @param array $optionalArgs { + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Task + * @return \Google\Cloud\Iam\V1\Policy * * @throws ApiException if the remote call fails + * * @experimental */ - public function renewLease($name, $scheduleTime, $leaseDuration, array $optionalArgs = []) + public function setIamPolicy($resource, $policy, array $optionalArgs = []) { - $request = new RenewLeaseRequest(); - $request->setName($name); - $request->setScheduleTime($scheduleTime); - $request->setLeaseDuration($leaseDuration); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'RenewLease', - Task::class, - $optionalArgs, - $request - )->wait(); + $request = new SetIamPolicyRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $request->setPolicy($policy); + $requestParamHeaders['resource'] = $resource; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('SetIamPolicy', Policy::class, $optionalArgs, $request)->wait(); } /** - * Cancel a pull task's lease. + * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. + * If the resource does not exist, this will return an empty set of + * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. * - * The worker can use this method to cancel a task's lease by - * setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will - * make the task available to be leased to the next caller of - * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. + * 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: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $scheduleTime = new Timestamp(); - * $response = $cloudTasksClient->cancelLease($formattedName, $scheduleTime); + * $resource = 'resource'; + * $permissions = []; + * $response = $cloudTasksClient->testIamPermissions($resource, $permissions); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` - * @param Timestamp $scheduleTime Required. The task's current schedule time, available in the - * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by - * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or - * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is - * to ensure that your worker currently holds the lease. - * @param array $optionalArgs { - * Optional. + * @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[] $permissions The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + * @param array $optionalArgs { + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Task + * @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse * * @throws ApiException if the remote call fails + * * @experimental */ - public function cancelLease($name, $scheduleTime, array $optionalArgs = []) + public function testIamPermissions($resource, $permissions, array $optionalArgs = []) { - $request = new CancelLeaseRequest(); - $request->setName($name); - $request->setScheduleTime($scheduleTime); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CancelLease', - Task::class, - $optionalArgs, - $request - )->wait(); + $request = new TestIamPermissionsRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $request->setPermissions($permissions); + $requestParamHeaders['resource'] = $resource; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('TestIamPermissions', TestIamPermissionsResponse::class, $optionalArgs, $request)->wait(); } /** - * Forces a task to run now. - * - * When this method is called, Cloud Tasks will dispatch the task, even if - * the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or - * is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. - * - * This command is meant to be used for manual debugging. For - * example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed - * task after a fix has been made or to manually force a task to be - * dispatched now. - * - * The dispatched task is returned. That is, the task that is returned - * contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but - * before the task is received by its target. + * Updates a queue. * - * If Cloud Tasks receives a successful response from the task's - * target, then the task will be deleted; otherwise the task's - * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that - * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified - * in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig]. + * This method creates the queue if it does not exist and updates + * the queue if it does exist. * - * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns - * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a - * task that has already succeeded or permanently failed. + * 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. * - * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a - * [pull task][google.cloud.tasks.v2beta2.PullMessage]. + * WARNING: Using this method may have unintended side effects if you are + * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. + * Read + * [Overview of Queue Management and + * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using + * this method. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $response = $cloudTasksClient->runTask($formattedName); + * $queue = new Queue(); + * $response = $cloudTasksClient->updateQueue($queue); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` - * @param array $optionalArgs { - * Optional. + * @param Queue $queue Required. The queue to create or update. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta2.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta2\Task\View} + * The queue's [name][google.cloud.tasks.v2beta2.Queue.name] must be specified. + * + * Output only fields cannot be modified using UpdateQueue. + * Any value specified for an output only field will be ignored. + * The queue's [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed. + * @param array $optionalArgs { + * Optional. + * + * @type FieldMask $updateMask + * A mask used to specify which fields of the queue are being updated. + * + * If empty, then all fields will be updated. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta2\Task + * @return \Google\Cloud\Tasks\V2beta2\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function runTask($name, array $optionalArgs = []) + public function updateQueue($queue, array $optionalArgs = []) { - $request = new RunTaskRequest(); - $request->setName($name); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); + $request = new UpdateQueueRequest(); + $requestParamHeaders = []; + $request->setQueue($queue); + $requestParamHeaders['queue.name'] = $queue->getName(); + if (isset($optionalArgs['updateMask'])) { + $request->setUpdateMask($optionalArgs['updateMask']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'RunTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('UpdateQueue', Queue::class, $optionalArgs, $request)->wait(); } } diff --git a/Tasks/src/V2beta2/GetQueueRequest.php b/Tasks/src/V2beta2/GetQueueRequest.php index 7c0d80019d29..e4dc677a8139 100644 --- a/Tasks/src/V2beta2/GetQueueRequest.php +++ b/Tasks/src/V2beta2/GetQueueRequest.php @@ -92,7 +92,7 @@ public function setName($var) */ public function getReadMask() { - return isset($this->read_mask) ? $this->read_mask : null; + return $this->read_mask; } public function hasReadMask() diff --git a/Tasks/src/V2beta2/LeaseTasksRequest.php b/Tasks/src/V2beta2/LeaseTasksRequest.php index f695cf9e0eac..3db2f182af56 100644 --- a/Tasks/src/V2beta2/LeaseTasksRequest.php +++ b/Tasks/src/V2beta2/LeaseTasksRequest.php @@ -257,7 +257,7 @@ public function setMaxTasks($var) */ public function getLeaseDuration() { - return isset($this->lease_duration) ? $this->lease_duration : null; + return $this->lease_duration; } public function hasLeaseDuration() diff --git a/Tasks/src/V2beta2/ListQueuesRequest.php b/Tasks/src/V2beta2/ListQueuesRequest.php index dbcae7ebae9e..d5d88b1e71b3 100644 --- a/Tasks/src/V2beta2/ListQueuesRequest.php +++ b/Tasks/src/V2beta2/ListQueuesRequest.php @@ -270,7 +270,7 @@ public function setPageToken($var) */ public function getReadMask() { - return isset($this->read_mask) ? $this->read_mask : null; + return $this->read_mask; } public function hasReadMask() diff --git a/Tasks/src/V2beta2/Queue.php b/Tasks/src/V2beta2/Queue.php index 7b1e8792f237..6e35efe3e5d9 100644 --- a/Tasks/src/V2beta2/Queue.php +++ b/Tasks/src/V2beta2/Queue.php @@ -72,7 +72,7 @@ class Queue extends \Google\Protobuf\Internal\Message private $retry_config = null; /** * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta2.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -187,7 +187,7 @@ class Queue extends \Google\Protobuf\Internal\Message * documentation](https://cloud.google.com/appengine/docs/standard/python/taskqueue/push/retrying-tasks). * @type int $state * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta2.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -374,7 +374,7 @@ public function setPullTarget($var) */ public function getRateLimits() { - return isset($this->rate_limits) ? $this->rate_limits : null; + return $this->rate_limits; } public function hasRateLimits() @@ -430,7 +430,7 @@ public function setRateLimits($var) */ public function getRetryConfig() { - return isset($this->retry_config) ? $this->retry_config : null; + return $this->retry_config; } public function hasRetryConfig() @@ -468,7 +468,7 @@ public function setRetryConfig($var) /** * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta2.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -484,7 +484,7 @@ public function getState() /** * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta2.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -517,7 +517,7 @@ public function setState($var) */ public function getPurgeTime() { - return isset($this->purge_time) ? $this->purge_time : null; + return $this->purge_time; } public function hasPurgeTime() @@ -569,7 +569,7 @@ public function setPurgeTime($var) */ public function getTaskTtl() { - return isset($this->task_ttl) ? $this->task_ttl : null; + return $this->task_ttl; } public function hasTaskTtl() @@ -621,7 +621,7 @@ public function setTaskTtl($var) */ public function getTombstoneTtl() { - return isset($this->tombstone_ttl) ? $this->tombstone_ttl : null; + return $this->tombstone_ttl; } public function hasTombstoneTtl() @@ -666,7 +666,7 @@ public function setTombstoneTtl($var) */ public function getStats() { - return isset($this->stats) ? $this->stats : null; + return $this->stats; } public function hasStats() diff --git a/Tasks/src/V2beta2/QueueStats.php b/Tasks/src/V2beta2/QueueStats.php index fef4024c452e..1f240180f60a 100644 --- a/Tasks/src/V2beta2/QueueStats.php +++ b/Tasks/src/V2beta2/QueueStats.php @@ -130,7 +130,7 @@ public function setTasksCount($var) */ public function getOldestEstimatedArrivalTime() { - return isset($this->oldest_estimated_arrival_time) ? $this->oldest_estimated_arrival_time : null; + return $this->oldest_estimated_arrival_time; } public function hasOldestEstimatedArrivalTime() diff --git a/Tasks/src/V2beta2/RenewLeaseRequest.php b/Tasks/src/V2beta2/RenewLeaseRequest.php index e9c04cd16b79..42cb7dd6e248 100644 --- a/Tasks/src/V2beta2/RenewLeaseRequest.php +++ b/Tasks/src/V2beta2/RenewLeaseRequest.php @@ -134,7 +134,7 @@ public function setName($var) */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -176,7 +176,7 @@ public function setScheduleTime($var) */ public function getLeaseDuration() { - return isset($this->lease_duration) ? $this->lease_duration : null; + return $this->lease_duration; } public function hasLeaseDuration() diff --git a/Tasks/src/V2beta2/RetryConfig.php b/Tasks/src/V2beta2/RetryConfig.php index 2b27bdc4d086..1edf24a4da3c 100644 --- a/Tasks/src/V2beta2/RetryConfig.php +++ b/Tasks/src/V2beta2/RetryConfig.php @@ -271,7 +271,7 @@ public function setUnlimitedAttempts($var) */ public function getMaxRetryDuration() { - return isset($this->max_retry_duration) ? $this->max_retry_duration : null; + return $this->max_retry_duration; } public function hasMaxRetryDuration() @@ -331,7 +331,7 @@ public function setMaxRetryDuration($var) */ public function getMinBackoff() { - return isset($this->min_backoff) ? $this->min_backoff : null; + return $this->min_backoff; } public function hasMinBackoff() @@ -389,7 +389,7 @@ public function setMinBackoff($var) */ public function getMaxBackoff() { - return isset($this->max_backoff) ? $this->max_backoff : null; + return $this->max_backoff; } public function hasMaxBackoff() diff --git a/Tasks/src/V2beta2/Task.php b/Tasks/src/V2beta2/Task.php index 7a2655e503c6..6768a79ca20a 100644 --- a/Tasks/src/V2beta2/Task.php +++ b/Tasks/src/V2beta2/Task.php @@ -274,7 +274,7 @@ public function setPullMessage($var) */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -317,7 +317,7 @@ public function setScheduleTime($var) */ public function getCreateTime() { - return isset($this->create_time) ? $this->create_time : null; + return $this->create_time; } public function hasCreateTime() @@ -354,7 +354,7 @@ public function setCreateTime($var) */ public function getStatus() { - return isset($this->status) ? $this->status : null; + return $this->status; } public function hasStatus() diff --git a/Tasks/src/V2beta2/TaskStatus.php b/Tasks/src/V2beta2/TaskStatus.php index 136c27d631fa..92d26851eb74 100644 --- a/Tasks/src/V2beta2/TaskStatus.php +++ b/Tasks/src/V2beta2/TaskStatus.php @@ -144,7 +144,7 @@ public function setAttemptResponseCount($var) */ public function getFirstAttemptStatus() { - return isset($this->first_attempt_status) ? $this->first_attempt_status : null; + return $this->first_attempt_status; } public function hasFirstAttemptStatus() @@ -184,7 +184,7 @@ public function setFirstAttemptStatus($var) */ public function getLastAttemptStatus() { - return isset($this->last_attempt_status) ? $this->last_attempt_status : null; + return $this->last_attempt_status; } public function hasLastAttemptStatus() diff --git a/Tasks/src/V2beta2/UpdateQueueRequest.php b/Tasks/src/V2beta2/UpdateQueueRequest.php index c8e9510366f3..d1604fd36dfa 100644 --- a/Tasks/src/V2beta2/UpdateQueueRequest.php +++ b/Tasks/src/V2beta2/UpdateQueueRequest.php @@ -67,7 +67,7 @@ public function __construct($data = NULL) { */ public function getQueue() { - return isset($this->queue) ? $this->queue : null; + return $this->queue; } public function hasQueue() @@ -108,7 +108,7 @@ public function setQueue($var) */ public function getUpdateMask() { - return isset($this->update_mask) ? $this->update_mask : null; + return $this->update_mask; } public function hasUpdateMask() diff --git a/Tasks/src/V2beta2/gapic_metadata.json b/Tasks/src/V2beta2/gapic_metadata.json new file mode 100644 index 000000000000..6faa81e5bd33 --- /dev/null +++ b/Tasks/src/V2beta2/gapic_metadata.json @@ -0,0 +1,118 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services\/RPCs to the corresponding library clients\/methods", + "language": "php", + "protoPackage": "google.cloud.tasks.v2beta2", + "libraryPackage": "Google\\Cloud\\Tasks\\V2beta2", + "services": { + "CloudTasks": { + "clients": { + "grpc": { + "libraryClient": "CloudTasksGapicClient", + "rpcs": { + "AcknowledgeTask": { + "methods": [ + "acknowledgeTask" + ] + }, + "CancelLease": { + "methods": [ + "cancelLease" + ] + }, + "CreateQueue": { + "methods": [ + "createQueue" + ] + }, + "CreateTask": { + "methods": [ + "createTask" + ] + }, + "DeleteQueue": { + "methods": [ + "deleteQueue" + ] + }, + "DeleteTask": { + "methods": [ + "deleteTask" + ] + }, + "GetIamPolicy": { + "methods": [ + "getIamPolicy" + ] + }, + "GetQueue": { + "methods": [ + "getQueue" + ] + }, + "GetTask": { + "methods": [ + "getTask" + ] + }, + "LeaseTasks": { + "methods": [ + "leaseTasks" + ] + }, + "ListQueues": { + "methods": [ + "listQueues" + ] + }, + "ListTasks": { + "methods": [ + "listTasks" + ] + }, + "PauseQueue": { + "methods": [ + "pauseQueue" + ] + }, + "PurgeQueue": { + "methods": [ + "purgeQueue" + ] + }, + "RenewLease": { + "methods": [ + "renewLease" + ] + }, + "ResumeQueue": { + "methods": [ + "resumeQueue" + ] + }, + "RunTask": { + "methods": [ + "runTask" + ] + }, + "SetIamPolicy": { + "methods": [ + "setIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "testIamPermissions" + ] + }, + "UpdateQueue": { + "methods": [ + "updateQueue" + ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Tasks/src/V2beta2/resources/cloud_tasks_client_config.json b/Tasks/src/V2beta2/resources/cloud_tasks_client_config.json index 755c0e81639f..ea9b38e559d2 100644 --- a/Tasks/src/V2beta2/resources/cloud_tasks_client_config.json +++ b/Tasks/src/V2beta2/resources/cloud_tasks_client_config.json @@ -1,145 +1,145 @@ { - "interfaces": { - "google.cloud.tasks.v2beta2.CloudTasks": { - "retry_codes": { - "retry_policy_1_codes": [ - "UNAVAILABLE", - "DEADLINE_EXCEEDED" - ], - "no_retry_codes": [], - "no_retry_1_codes": [] - }, - "retry_params": { - "retry_policy_1_params": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 10000, - "initial_rpc_timeout_millis": 20000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 20000, - "total_timeout_millis": 20000 - }, - "no_retry_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 0, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 0, - "total_timeout_millis": 0 - }, - "no_retry_1_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 20000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 20000, - "total_timeout_millis": 20000 + "interfaces": { + "google.cloud.tasks.v2beta2.CloudTasks": { + "retry_codes": { + "no_retry_codes": [], + "retry_policy_1_codes": [ + "UNAVAILABLE", + "DEADLINE_EXCEEDED" + ], + "no_retry_1_codes": [] + }, + "retry_params": { + "no_retry_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 0, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 0, + "total_timeout_millis": 0 + }, + "retry_policy_1_params": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 10000, + "initial_rpc_timeout_millis": 20000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 20000, + "total_timeout_millis": 20000 + }, + "no_retry_1_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 20000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 20000, + "total_timeout_millis": 20000 + } + }, + "methods": { + "AcknowledgeTask": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "CancelLease": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "CreateQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "CreateTask": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "DeleteQueue": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "DeleteTask": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetIamPolicy": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetQueue": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetTask": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "LeaseTasks": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "ListQueues": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListTasks": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "PauseQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "PurgeQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "RenewLease": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "ResumeQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "RunTask": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "SetIamPolicy": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "TestIamPermissions": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "UpdateQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + } + } } - }, - "methods": { - "ListQueues": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "GetQueue": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "CreateQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "UpdateQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "DeleteQueue": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "PurgeQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "PauseQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "ResumeQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "GetIamPolicy": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "SetIamPolicy": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "TestIamPermissions": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "ListTasks": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "GetTask": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "CreateTask": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "DeleteTask": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "LeaseTasks": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "AcknowledgeTask": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "RenewLease": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "CancelLease": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "RunTask": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - } - } } - } } diff --git a/Tasks/src/V2beta2/resources/cloud_tasks_rest_client_config.php b/Tasks/src/V2beta2/resources/cloud_tasks_rest_client_config.php index 4ebf3cbc4840..795331d094d2 100644 --- a/Tasks/src/V2beta2/resources/cloud_tasks_rest_client_config.php +++ b/Tasks/src/V2beta2/resources/cloud_tasks_rest_client_config.php @@ -3,20 +3,22 @@ return [ 'interfaces' => [ 'google.cloud.tasks.v2beta2.CloudTasks' => [ - 'ListQueues' => [ - 'method' => 'get', - 'uriTemplate' => '/v2beta2/{parent=projects/*/locations/*}/queues', + 'AcknowledgeTask' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:acknowledge', + 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'GetQueue' => [ - 'method' => 'get', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}', + 'CancelLease' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:cancelLease', + 'body' => '*', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -37,15 +39,14 @@ ], ], ], - 'UpdateQueue' => [ - 'method' => 'patch', - 'uriTemplate' => '/v2beta2/{queue.name=projects/*/locations/*/queues/*}', - 'body' => 'queue', + 'CreateTask' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks', + 'body' => '*', 'placeholders' => [ - 'queue.name' => [ + 'parent' => [ 'getters' => [ - 'getQueue', - 'getName', + 'getParent', ], ], ], @@ -61,10 +62,9 @@ ], ], ], - 'PurgeQueue' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}:purge', - 'body' => '*', + 'DeleteTask' => [ + 'method' => 'delete', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -73,22 +73,21 @@ ], ], ], - 'PauseQueue' => [ + 'GetIamPolicy' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}:pause', + 'uriTemplate' => '/v2beta2/{resource=projects/*/locations/*/queues/*}:getIamPolicy', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'ResumeQueue' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}:resume', - 'body' => '*', + 'GetQueue' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -97,38 +96,36 @@ ], ], ], - 'GetIamPolicy' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta2/{resource=projects/*/locations/*/queues/*}:getIamPolicy', - 'body' => '*', + 'GetTask' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}', 'placeholders' => [ - 'resource' => [ + 'name' => [ 'getters' => [ - 'getResource', + 'getName', ], ], ], ], - 'SetIamPolicy' => [ + 'LeaseTasks' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{resource=projects/*/locations/*/queues/*}:setIamPolicy', + 'uriTemplate' => '/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks:lease', 'body' => '*', 'placeholders' => [ - 'resource' => [ + 'parent' => [ 'getters' => [ - 'getResource', + 'getParent', ], ], ], ], - 'TestIamPermissions' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta2/{resource=projects/*/locations/*/queues/*}:testIamPermissions', - 'body' => '*', + 'ListQueues' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta2/{parent=projects/*/locations/*}/queues', 'placeholders' => [ - 'resource' => [ + 'parent' => [ 'getters' => [ - 'getResource', + 'getParent', ], ], ], @@ -144,9 +141,10 @@ ], ], ], - 'GetTask' => [ - 'method' => 'get', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}', + 'PauseQueue' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}:pause', + 'body' => '*', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -155,21 +153,22 @@ ], ], ], - 'CreateTask' => [ + 'PurgeQueue' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}:purge', 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'DeleteTask' => [ - 'method' => 'delete', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}', + 'RenewLease' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:renewLease', + 'body' => '*', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -178,21 +177,21 @@ ], ], ], - 'LeaseTasks' => [ + 'ResumeQueue' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks:lease', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*}:resume', 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'AcknowledgeTask' => [ + 'RunTask' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:acknowledge', + 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:run', 'body' => '*', 'placeholders' => [ 'name' => [ @@ -202,37 +201,38 @@ ], ], ], - 'RenewLease' => [ + 'SetIamPolicy' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:renewLease', + 'uriTemplate' => '/v2beta2/{resource=projects/*/locations/*/queues/*}:setIamPolicy', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'CancelLease' => [ + 'TestIamPermissions' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:cancelLease', + 'uriTemplate' => '/v2beta2/{resource=projects/*/locations/*/queues/*}:testIamPermissions', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'RunTask' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:run', - 'body' => '*', + 'UpdateQueue' => [ + 'method' => 'patch', + 'uriTemplate' => '/v2beta2/{queue.name=projects/*/locations/*/queues/*}', + 'body' => 'queue', 'placeholders' => [ - 'name' => [ + 'queue.name' => [ 'getters' => [ + 'getQueue', 'getName', ], ], diff --git a/Tasks/src/V2beta3/AppEngineHttpQueue.php b/Tasks/src/V2beta3/AppEngineHttpQueue.php index 8ef0f1e2b527..f3bb59e6f4da 100644 --- a/Tasks/src/V2beta3/AppEngineHttpQueue.php +++ b/Tasks/src/V2beta3/AppEngineHttpQueue.php @@ -66,7 +66,7 @@ public function __construct($data = NULL) { */ public function getAppEngineRoutingOverride() { - return isset($this->app_engine_routing_override) ? $this->app_engine_routing_override : null; + return $this->app_engine_routing_override; } public function hasAppEngineRoutingOverride() diff --git a/Tasks/src/V2beta3/AppEngineHttpRequest.php b/Tasks/src/V2beta3/AppEngineHttpRequest.php index 04304336d0d6..c857f4347d99 100644 --- a/Tasks/src/V2beta3/AppEngineHttpRequest.php +++ b/Tasks/src/V2beta3/AppEngineHttpRequest.php @@ -264,7 +264,7 @@ public function setHttpMethod($var) */ public function getAppEngineRouting() { - return isset($this->app_engine_routing) ? $this->app_engine_routing : null; + return $this->app_engine_routing; } public function hasAppEngineRouting() diff --git a/Tasks/src/V2beta3/Attempt.php b/Tasks/src/V2beta3/Attempt.php index 06dce1f8e592..4fa901f83df8 100644 --- a/Tasks/src/V2beta3/Attempt.php +++ b/Tasks/src/V2beta3/Attempt.php @@ -80,7 +80,7 @@ public function __construct($data = NULL) { */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -118,7 +118,7 @@ public function setScheduleTime($var) */ public function getDispatchTime() { - return isset($this->dispatch_time) ? $this->dispatch_time : null; + return $this->dispatch_time; } public function hasDispatchTime() @@ -156,7 +156,7 @@ public function setDispatchTime($var) */ public function getResponseTime() { - return isset($this->response_time) ? $this->response_time : null; + return $this->response_time; } public function hasResponseTime() @@ -195,7 +195,7 @@ public function setResponseTime($var) */ public function getResponseStatus() { - return isset($this->response_status) ? $this->response_status : null; + return $this->response_status; } public function hasResponseStatus() diff --git a/Tasks/src/V2beta3/CloudTasksClient.php b/Tasks/src/V2beta3/CloudTasksClient.php index fb71d40ea5d5..19f8ce333fcd 100644 --- a/Tasks/src/V2beta3/CloudTasksClient.php +++ b/Tasks/src/V2beta3/CloudTasksClient.php @@ -17,9 +17,9 @@ /* * GENERATED CODE WARNING - * This file was generated from the file - * https://github.com/google/googleapis/blob/master/google/cloud/tasks/v2beta3/cloudtasks.proto - * and updates to that file get reflected here through a refresh process. + * Generated by gapic-generator-php from the file + * https://github.com/googleapis/googleapis/blob/master/google/cloud/tasks/v2beta3/cloudtasks.proto + * Updates to the above are reflected here through a refresh process. * * @experimental */ @@ -28,11 +28,9 @@ use Google\Cloud\Tasks\V2beta3\Gapic\CloudTasksGapicClient; -/** - * {@inheritdoc} - */ +/** {@inheritdoc} */ class CloudTasksClient extends CloudTasksGapicClient { - // This class is intentionally empty, and is intended to hold manual - // additions to the generated {@see CloudTasksGapicClient} class. + // This class is intentionally empty, and is intended to hold manual additions to + // the generated {@see CloudTasksGapicClient} class. } diff --git a/Tasks/src/V2beta3/CreateQueueRequest.php b/Tasks/src/V2beta3/CreateQueueRequest.php index b265b9fb6e73..50d220c64fb2 100644 --- a/Tasks/src/V2beta3/CreateQueueRequest.php +++ b/Tasks/src/V2beta3/CreateQueueRequest.php @@ -98,7 +98,7 @@ public function setParent($var) */ public function getQueue() { - return isset($this->queue) ? $this->queue : null; + return $this->queue; } public function hasQueue() diff --git a/Tasks/src/V2beta3/CreateTaskRequest.php b/Tasks/src/V2beta3/CreateTaskRequest.php index e479ed34662a..1d9e74da6416 100644 --- a/Tasks/src/V2beta3/CreateTaskRequest.php +++ b/Tasks/src/V2beta3/CreateTaskRequest.php @@ -194,7 +194,7 @@ public function setParent($var) */ public function getTask() { - return isset($this->task) ? $this->task : null; + return $this->task; } public function hasTask() diff --git a/Tasks/src/V2beta3/Gapic/CloudTasksGapicClient.php b/Tasks/src/V2beta3/Gapic/CloudTasksGapicClient.php index fdf6a894d017..e1214eb0e8c8 100644 --- a/Tasks/src/V2beta3/Gapic/CloudTasksGapicClient.php +++ b/Tasks/src/V2beta3/Gapic/CloudTasksGapicClient.php @@ -17,9 +17,9 @@ /* * GENERATED CODE WARNING - * This file was generated from the file - * https://github.com/google/googleapis/blob/master/google/cloud/tasks/v2beta3/cloudtasks.proto - * and updates to that file get reflected here through a refresh process. + * Generated by gapic-generator-php from the file + * https://github.com/googleapis/googleapis/blob/master/google/cloud/tasks/v2beta3/cloudtasks.proto + * Updates to the above are reflected here through a refresh process. * * @experimental */ @@ -29,6 +29,7 @@ use Google\ApiCore\ApiException; use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\GapicClientTrait; + use Google\ApiCore\PathTemplate; use Google\ApiCore\RequestParamsHeaderDescriptor; use Google\ApiCore\RetrySettings; @@ -73,31 +74,17 @@ * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * - * - * // Alternatively: - * - * // Iterate through all elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } + * $queue = new Queue(); + * $response = $cloudTasksClient->createQueue($formattedParent, $queue); * } finally { * $cloudTasksClient->close(); * } * ``` * - * 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. + * 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. * * @experimental */ @@ -131,26 +118,29 @@ class CloudTasksGapicClient public static $serviceScopes = [ 'https://www.googleapis.com/auth/cloud-platform', ]; + private static $locationNameTemplate; - private static $projectNameTemplate; + private static $queueNameTemplate; + private static $taskNameTemplate; + private static $pathTemplateMap; private static function getClientDefaults() { return [ 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS.':'.self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__.'/../resources/cloud_tasks_client_config.json', - 'descriptorsConfigPath' => __DIR__.'/../resources/cloud_tasks_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__.'/../resources/cloud_tasks_grpc_config.json', + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/cloud_tasks_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/cloud_tasks_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/cloud_tasks_grpc_config.json', 'credentialsConfig' => [ 'defaultScopes' => self::$serviceScopes, ], 'transportConfig' => [ 'rest' => [ - 'restClientConfigPath' => __DIR__.'/../resources/cloud_tasks_rest_client_config.php', + 'restClientConfigPath' => __DIR__ . '/../resources/cloud_tasks_rest_client_config.php', ], ], ]; @@ -158,7 +148,7 @@ private static function getClientDefaults() private static function getLocationNameTemplate() { - if (null == self::$locationNameTemplate) { + if (self::$locationNameTemplate == null) { self::$locationNameTemplate = new PathTemplate('projects/{project}/locations/{location}'); } @@ -176,7 +166,7 @@ private static function getProjectNameTemplate() private static function getQueueNameTemplate() { - if (null == self::$queueNameTemplate) { + if (self::$queueNameTemplate == null) { self::$queueNameTemplate = new PathTemplate('projects/{project}/locations/{location}/queues/{queue}'); } @@ -185,7 +175,7 @@ private static function getQueueNameTemplate() private static function getTaskNameTemplate() { - if (null == self::$taskNameTemplate) { + if (self::$taskNameTemplate == null) { self::$taskNameTemplate = new PathTemplate('projects/{project}/locations/{location}/queues/{queue}/tasks/{task}'); } @@ -194,7 +184,7 @@ private static function getTaskNameTemplate() private static function getPathTemplateMap() { - if (null == self::$pathTemplateMap) { + if (self::$pathTemplateMap == null) { self::$pathTemplateMap = [ 'location' => self::getLocationNameTemplate(), 'project' => self::getProjectNameTemplate(), @@ -207,13 +197,14 @@ private static function getPathTemplateMap() } /** - * Formats a string containing the fully-qualified path to represent - * a location resource. + * Formats a string containing the fully-qualified path to represent a location + * resource. * * @param string $project * @param string $location * * @return string The formatted location resource. + * * @experimental */ public static function locationName($project, $location) @@ -225,14 +216,15 @@ public static function locationName($project, $location) } /** - * Formats a string containing the fully-qualified path to represent - * a queue resource. + * Formats a string containing the fully-qualified path to represent a queue + * resource. * * @param string $project * @param string $location * @param string $queue * * @return string The formatted queue resource. + * * @experimental */ public static function queueName($project, $location, $queue) @@ -245,8 +237,8 @@ public static function queueName($project, $location, $queue) } /** - * Formats a string containing the fully-qualified path to represent - * a task resource. + * Formats a string containing the fully-qualified path to represent a task + * resource. * * @param string $project * @param string $location @@ -254,6 +246,7 @@ public static function queueName($project, $location, $queue) * @param string $task * * @return string The formatted task resource. + * * @experimental */ public static function taskName($project, $location, $queue, $task) @@ -287,12 +280,13 @@ public static function projectName($project) * Template: Pattern * - location: projects/{project}/locations/{location} * - queue: projects/{project}/locations/{location}/queues/{queue} - * - task: projects/{project}/locations/{location}/queues/{queue}/tasks/{task}. + * - 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. + * 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. * * @param string $formattedName The formatted name string * @param string $template Optional name of template to match @@ -300,12 +294,12 @@ public static function projectName($project) * @return array An associative array from name component IDs to component values. * * @throws ValidationException If $formattedName could not be matched. + * * @experimental */ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if ($template) { if (!isset($templateMap[$template])) { throw new ValidationException("Template name $template does not exist"); @@ -321,6 +315,7 @@ public static function parseName($formattedName, $template = null) // Swallow the exception to continue trying other path templates } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } @@ -328,7 +323,7 @@ public static function parseName($formattedName, $template = null) * Constructor. * * @param array $options { - * Optional. Options for configuring the service API wrapper. + * Optional. Options for configuring the service API wrapper. * * @type string $serviceAddress * **Deprecated**. This option will be removed in a future major release. Please @@ -345,38 +340,42 @@ public static function parseName($formattedName, $template = null) * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these * objects are provided, any settings in $credentialsConfig will be ignored. * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the client. - * For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()}. + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . * @type bool $disableRetries * Determines whether or not retries defined by the client configuration should be * disabled. Defaults to `false`. * @type string|array $clientConfig - * 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. + * 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. * @type string|TransportInterface $transport - * 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 - * {@see \Google\ApiCore\Transport\TransportInterface} object. Note that when this - * object is provided, any settings in $transportConfig, and any `$apiEndpoint` - * setting, will be ignored. + * 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 {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $serviceAddress setting, will be ignored. * @type array $transportConfig * 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' => [...] + * 'rest' => [...], * ]; * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the * supported options. + * @type callable $clientCertSource + * 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. * } * * @throws ValidationException + * * @experimental */ public function __construct(array $options = []) @@ -385,171 +384,6 @@ public function __construct(array $options = []) $this->setClientOptions($clientOptions); } - /** - * Lists queues. - * - * Queues are returned in lexicographical order. - * - * Sample code: - * ``` - * $cloudTasksClient = new CloudTasksClient(); - * try { - * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * - * - * // Alternatively: - * - * // Iterate through all elements - * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $cloudTasksClient->close(); - * } - * ``` - * - * @param string $parent Required. The location name. - * For example: `projects/PROJECT_ID/locations/LOCATION_ID` - * @param array $optionalArgs { - * Optional. - * - * @type string $filter - * `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2beta3.Queue] - * field can be used as a filter and several operators as supported. - * For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as - * described in - * [Stackdriver's Advanced Logs - * Filters](https://cloud.google.com/logging/docs/view/advanced_filters). - * - * Sample filter "state: PAUSED". - * - * Note that using filters might cause fewer queues than the - * requested page_size to be returned. - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type FieldMask $readMask - * Optional. Read mask is used for a more granular control over what the API returns. - * If the mask is not present all fields will be returned except - * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly - * specified in the mask. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - * @experimental - */ - public function listQueues($parent, array $optionalArgs = []) - { - $request = new ListQueuesRequest(); - $request->setParent($parent); - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - if (isset($optionalArgs['readMask'])) { - $request->setReadMask($optionalArgs['readMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->getPagedListResponse( - 'ListQueues', - $optionalArgs, - ListQueuesResponse::class, - $request - ); - } - - /** - * Gets a queue. - * - * Sample code: - * ``` - * $cloudTasksClient = new CloudTasksClient(); - * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->getQueue($formattedName); - * } finally { - * $cloudTasksClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the queue. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * @param array $optionalArgs { - * Optional. - * - * @type FieldMask $readMask - * Optional. Read mask is used for a more granular control over what the API returns. - * If the mask is not present all fields will be returned except - * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly - * specified in the mask. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Tasks\V2beta3\Queue - * - * @throws ApiException if the remote call fails - * @experimental - */ - public function getQueue($name, array $optionalArgs = []) - { - $request = new GetQueueRequest(); - $request->setName($name); - if (isset($optionalArgs['readMask'])) { - $request->setReadMask($optionalArgs['readMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); - } - /** * Creates a queue. * @@ -576,126 +410,143 @@ public function getQueue($name, array $optionalArgs = []) * } * ``` * - * @param string $parent Required. The location name in which the queue will be created. - * For example: `projects/PROJECT_ID/locations/LOCATION_ID` + * @param string $parent Required. The location name in which the queue will be created. + * For example: `projects/PROJECT_ID/locations/LOCATION_ID` * - * The list of allowed locations can be obtained by calling Cloud - * Tasks' implementation of - * [ListLocations][google.cloud.location.Locations.ListLocations]. - * @param Queue $queue Required. The queue to create. + * The list of allowed locations can be obtained by calling Cloud + * Tasks' implementation of + * [ListLocations][google.cloud.location.Locations.ListLocations]. + * @param Queue $queue Required. The queue to create. * - * [Queue's name][google.cloud.tasks.v2beta3.Queue.name] cannot be the same as an existing queue. - * @param array $optionalArgs { - * Optional. + * [Queue's name][google.cloud.tasks.v2beta3.Queue.name] cannot be the same as an existing queue. + * @param array $optionalArgs { + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2beta3\Queue * * @throws ApiException if the remote call fails + * * @experimental */ public function createQueue($parent, $queue, array $optionalArgs = []) { $request = new CreateQueueRequest(); + $requestParamHeaders = []; $request->setParent($parent); $request->setQueue($queue); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CreateQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['parent'] = $parent; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CreateQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Updates a queue. - * - * This method creates the queue if it does not exist and updates - * the queue if it does exist. + * Creates a task and adds it to 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. + * Tasks cannot be updated after creation; there is no UpdateTask command. * - * WARNING: Using this method may have unintended side effects if you are - * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. - * Read - * [Overview of Queue Management and - * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using - * this method. + * * The maximum task size is 100KB. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $queue = new Queue(); - * $response = $cloudTasksClient->updateQueue($queue); + * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $task = new Task(); + * $response = $cloudTasksClient->createTask($formattedParent, $task); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param Queue $queue Required. The queue to create or update. - * - * The queue's [name][google.cloud.tasks.v2beta3.Queue.name] must be specified. - * - * Output only fields cannot be modified using UpdateQueue. - * Any value specified for an output only field will be ignored. - * The queue's [name][google.cloud.tasks.v2beta3.Queue.name] cannot be changed. - * @param array $optionalArgs { - * Optional. + * @param string $parent Required. The queue name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * - * @type FieldMask $updateMask - * A mask used to specify which fields of the queue are being updated. + * The queue must already exist. + * @param Task $task Required. The task to add. + * + * Task names have the following format: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. + * The user can optionally specify a task [name][google.cloud.tasks.v2beta3.Task.name]. If a + * name is not specified then the system will generate a random + * unique task id, which will be set in the task returned in the + * [response][google.cloud.tasks.v2beta3.Task.name]. + * + * If [schedule_time][google.cloud.tasks.v2beta3.Task.schedule_time] is not set or is in the + * past then Cloud Tasks will set it to the current time. + * + * Task De-duplication: + * + * Explicitly specifying a task ID enables task de-duplication. If + * a task's ID is identical to that of an existing task or a task + * that was deleted or executed recently then the call will fail + * with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. + * If the task's queue was created using Cloud Tasks, then another task with + * the same name can't be created for ~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][google.cloud.tasks.v2beta3.CloudTasks.CreateTask] calls have significantly + * increased latency. Using hashed strings for the task id or for + * the prefix of the task id is recommended. Choosing task ids that + * are sequential or have sequential prefixes, for example using a + * timestamp, causes an increase in latency and error rates in all + * task commands. The infrastructure relies on an approximately + * uniform distribution of task ids to store and serve tasks + * efficiently. + * @param array $optionalArgs { + * Optional. * - * If empty, then all fields will be updated. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta3\Queue + * @return \Google\Cloud\Tasks\V2beta3\Task * * @throws ApiException if the remote call fails + * * @experimental */ - public function updateQueue($queue, array $optionalArgs = []) + public function createTask($parent, $task, array $optionalArgs = []) { - $request = new UpdateQueueRequest(); - $request->setQueue($queue); - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); + $request = new CreateTaskRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $request->setTask($task); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'queue.name' => $request->getQueue()->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'UpdateQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CreateTask', Task::class, $optionalArgs, $request)->wait(); } /** @@ -727,407 +578,343 @@ public function updateQueue($queue, array $optionalArgs = []) * @param string $name Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @throws ApiException if the remote call fails + * * @experimental */ public function deleteQueue($name, array $optionalArgs = []) { $request = new DeleteQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'DeleteQueue', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteQueue', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Purges a queue by deleting all of its tasks. - * - * All tasks created before this method is called are permanently deleted. + * Deletes a task. * - * Purge operations can take up to one minute to take effect. Tasks - * might be dispatched before the purge takes effect. A purge is irreversible. + * 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: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->purgeQueue($formattedName); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $cloudTasksClient->deleteTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta3\Queue - * * @throws ApiException if the remote call fails + * * @experimental */ - public function purgeQueue($name, array $optionalArgs = []) + public function deleteTask($name, array $optionalArgs = []) { - $request = new PurgeQueueRequest(); + $request = new DeleteTaskRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'PurgeQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteTask', GPBEmpty::class, $optionalArgs, $request)->wait(); } /** - * Pauses the queue. + * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta3.Queue]. + * Returns an empty policy if the resource exists and does not have a policy + * set. * - * If a queue is paused then the system will stop dispatching tasks - * until the queue is resumed via - * [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue]. Tasks can still be added - * when the queue is paused. A queue is paused if its - * [state][google.cloud.tasks.v2beta3.Queue.state] is [PAUSED][google.cloud.tasks.v2beta3.Queue.State.PAUSED]. + * Authorization requires the following + * [Google IAM](https://cloud.google.com/iam) permission on the specified + * resource parent: + * + * * `cloudtasks.queues.getIamPolicy` * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->pauseQueue($formattedName); + * $resource = 'resource'; + * $response = $cloudTasksClient->getIamPolicy($resource); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $resource REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. * @param array $optionalArgs { - * Optional. + * Optional. * + * @type GetPolicyOptions $options + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta3\Queue + * @return \Google\Cloud\Iam\V1\Policy * * @throws ApiException if the remote call fails + * * @experimental */ - public function pauseQueue($name, array $optionalArgs = []) + public function getIamPolicy($resource, array $optionalArgs = []) { - $request = new PauseQueueRequest(); - $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); + $request = new GetIamPolicyRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $requestParamHeaders['resource'] = $resource; + if (isset($optionalArgs['options'])) { + $request->setOptions($optionalArgs['options']); + } - return $this->startCall( - 'PauseQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetIamPolicy', Policy::class, $optionalArgs, $request)->wait(); } /** - * Resume a queue. - * - * This method resumes a queue after it has been - * [PAUSED][google.cloud.tasks.v2beta3.Queue.State.PAUSED] or - * [DISABLED][google.cloud.tasks.v2beta3.Queue.State.DISABLED]. The state of a queue is stored - * in the queue's [state][google.cloud.tasks.v2beta3.Queue.state]; after calling this method it - * will be set to [RUNNING][google.cloud.tasks.v2beta3.Queue.State.RUNNING]. - * - * WARNING: Resuming many high-QPS queues at the same time can - * lead to target overloading. If you are resuming high-QPS - * queues, follow the 500/50/5 pattern described in - * [Managing Cloud Tasks Scaling - * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). + * Gets a queue. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $response = $cloudTasksClient->resumeQueue($formattedName); + * $response = $cloudTasksClient->getQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The queue name. For example: - * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param string $name Required. The resource name of the queue. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * + * @type FieldMask $readMask + * Optional. Read mask is used for a more granular control over what the API returns. + * If the mask is not present all fields will be returned except + * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + * specified in the mask. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2beta3\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function resumeQueue($name, array $optionalArgs = []) + public function getQueue($name, array $optionalArgs = []) { - $request = new ResumeQueueRequest(); + $request = new GetQueueRequest(); + $requestParamHeaders = []; $request->setName($name); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['readMask'])) { + $request->setReadMask($optionalArgs['readMask']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'ResumeQueue', - Queue::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta3.Queue]. - * Returns an empty policy if the resource exists and does not have a policy - * set. - * - * Authorization requires the following - * [Google IAM](https://cloud.google.com/iam) permission on the specified - * resource parent: - * - * * `cloudtasks.queues.getIamPolicy` + * Gets a task. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $response = $cloudTasksClient->getIamPolicy($resource); + * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + * $response = $cloudTasksClient->getTask($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $resource REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. + * @param string $name Required. The task name. For example: + * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * - * @type GetPolicyOptions $options - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. This field is only used by Cloud IAM. + * @type int $responseView + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\Policy + * @return \Google\Cloud\Tasks\V2beta3\Task * * @throws ApiException if the remote call fails + * * @experimental */ - public function getIamPolicy($resource, array $optionalArgs = []) + public function getTask($name, array $optionalArgs = []) { - $request = new GetIamPolicyRequest(); - $request->setResource($resource); - if (isset($optionalArgs['options'])) { - $request->setOptions($optionalArgs['options']); + $request = new GetTaskRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['responseView'])) { + $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetIamPolicy', - Policy::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetTask', Task::class, $optionalArgs, $request)->wait(); } /** - * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta3.Queue]. Replaces any existing - * policy. - * - * Note: The Cloud Console does not check queue-level IAM permissions yet. - * Project-level permissions are required to use the Cloud Console. - * - * Authorization requires the following - * [Google IAM](https://cloud.google.com/iam) permission on the specified - * resource parent: + * Lists queues. * - * * `cloudtasks.queues.setIamPolicy` + * Queues are returned in lexicographical order. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $resource = ''; - * $policy = new Policy(); - * $response = $cloudTasksClient->setIamPolicy($resource, $policy); + * $formattedParent = $cloudTasksClient->locationName('[PROJECT]', '[LOCATION]'); + * // Iterate over pages of elements + * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $cloudTasksClient->listQueues($formattedParent); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $resource REQUIRED: The resource for which the policy is being specified. - * See the operation documentation for the appropriate value for this field. - * @param Policy $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. + * @param string $parent Required. The location name. + * For example: `projects/PROJECT_ID/locations/LOCATION_ID` * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Iam\V1\Policy - * - * @throws ApiException if the remote call fails - * @experimental - */ - public function setIamPolicy($resource, $policy, array $optionalArgs = []) - { - $request = new SetIamPolicyRequest(); - $request->setResource($resource); - $request->setPolicy($policy); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'SetIamPolicy', - Policy::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta3.Queue]. - * If the resource does not exist, this will return an empty set of - * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. - * - * Note: This operation is designed to be used for building permission-aware - * UIs and command-line tools, not for authorization checking. This operation - * may "fail open" without warning. + * Optional. * - * Sample code: - * ``` - * $cloudTasksClient = new CloudTasksClient(); - * try { - * $resource = ''; - * $permissions = []; - * $response = $cloudTasksClient->testIamPermissions($resource, $permissions); - * } finally { - * $cloudTasksClient->close(); - * } - * ``` + * @type string $filter + * `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2beta3.Queue] + * field can be used as a filter and several operators as supported. + * For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as + * described in + * [Stackdriver's Advanced Logs + * Filters](https://cloud.google.com/logging/docs/view/advanced_filters). * - * @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[] $permissions The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see - * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). - * @param array $optionalArgs { - * Optional. + * Sample filter "state: PAUSED". * + * Note that using filters might cause fewer queues than the + * requested page_size to be returned. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type FieldMask $readMask + * Optional. Read mask is used for a more granular control over what the API returns. + * If the mask is not present all fields will be returned except + * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + * specified in the mask. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse + * @return \Google\ApiCore\PagedListResponse * * @throws ApiException if the remote call fails + * * @experimental */ - public function testIamPermissions($resource, $permissions, array $optionalArgs = []) + public function listQueues($parent, array $optionalArgs = []) { - $request = new TestIamPermissionsRequest(); - $request->setResource($resource); - $request->setPermissions($permissions); + $request = new ListQueuesRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } - $requestParams = new RequestParamsHeaderDescriptor([ - 'resource' => $request->getResource(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } - return $this->startCall( - 'TestIamPermissions', - TestIamPermissionsResponse::class, - $optionalArgs, - $request - )->wait(); + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + if (isset($optionalArgs['readMask'])) { + $request->setReadMask($optionalArgs['readMask']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListQueues', $optionalArgs, ListQueuesResponse::class, $request); } /** @@ -1153,10 +940,7 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs * // doSomethingWith($element); * } * } - * - * * // Alternatively: - * * // Iterate through all elements * $pagedResponse = $cloudTasksClient->listTasks($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -1170,300 +954,217 @@ public function testIamPermissions($resource, $permissions, array $optionalArgs * @param string $parent Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\ApiCore\PagedListResponse * * @throws ApiException if the remote call fails + * * @experimental */ public function listTasks($parent, array $optionalArgs = []) { $request = new ListTasksRequest(); + $requestParamHeaders = []; $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; if (isset($optionalArgs['responseView'])) { $request->setResponseView($optionalArgs['responseView']); } + if (isset($optionalArgs['pageSize'])) { $request->setPageSize($optionalArgs['pageSize']); } + if (isset($optionalArgs['pageToken'])) { $request->setPageToken($optionalArgs['pageToken']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->getPagedListResponse( - 'ListTasks', - $optionalArgs, - ListTasksResponse::class, - $request - ); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListTasks', $optionalArgs, ListTasksResponse::class, $request); } /** - * Gets a task. + * Pauses the queue. + * + * If a queue is paused then the system will stop dispatching tasks + * until the queue is resumed via + * [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue]. Tasks can still be added + * when the queue is paused. A queue is paused if its + * [state][google.cloud.tasks.v2beta3.Queue.state] is [PAUSED][google.cloud.tasks.v2beta3.Queue.State.PAUSED]. * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $response = $cloudTasksClient->getTask($formattedName); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->pauseQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta3\Task + * @return \Google\Cloud\Tasks\V2beta3\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function getTask($name, array $optionalArgs = []) + public function pauseQueue($name, array $optionalArgs = []) { - $request = new GetTaskRequest(); + $request = new PauseQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'GetTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PauseQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Creates a task and adds it to a queue. + * Purges a queue by deleting all of its tasks. * - * Tasks cannot be updated after creation; there is no UpdateTask command. + * All tasks created before this method is called are permanently deleted. * - * * The maximum task size is 100KB. + * 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: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedParent = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - * $task = new Task(); - * $response = $cloudTasksClient->createTask($formattedParent, $task); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->purgeQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $parent Required. The queue name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` - * - * The queue must already exist. - * @param Task $task Required. The task to add. - * - * Task names have the following format: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. - * The user can optionally specify a task [name][google.cloud.tasks.v2beta3.Task.name]. If a - * name is not specified then the system will generate a random - * unique task id, which will be set in the task returned in the - * [response][google.cloud.tasks.v2beta3.Task.name]. - * - * If [schedule_time][google.cloud.tasks.v2beta3.Task.schedule_time] is not set or is in the - * past then Cloud Tasks will set it to the current time. - * - * Task De-duplication: - * - * Explicitly specifying a task ID enables task de-duplication. If - * a task's ID is identical to that of an existing task or a task - * that was deleted or executed recently then the call will fail - * with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. - * If the task's queue was created using Cloud Tasks, then another task with - * the same name can't be created for ~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][google.cloud.tasks.v2beta3.CloudTasks.CreateTask] calls have significantly - * increased latency. Using hashed strings for the task id or for - * the prefix of the task id is recommended. Choosing task ids that - * are sequential or have sequential prefixes, for example using a - * timestamp, causes an increase in latency and error rates in all - * task commands. The infrastructure relies on an approximately - * uniform distribution of task ids to store and serve tasks - * efficiently. - * @param array $optionalArgs { - * Optional. + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` + * @param array $optionalArgs { + * Optional. * - * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * - * @return \Google\Cloud\Tasks\V2beta3\Task + * @return \Google\Cloud\Tasks\V2beta3\Queue * * @throws ApiException if the remote call fails + * * @experimental */ - public function createTask($parent, $task, array $optionalArgs = []) + public function purgeQueue($name, array $optionalArgs = []) { - $request = new CreateTaskRequest(); - $request->setParent($parent); - $request->setTask($task); - if (isset($optionalArgs['responseView'])) { - $request->setResponseView($optionalArgs['responseView']); - } - - $requestParams = new RequestParamsHeaderDescriptor([ - 'parent' => $request->getParent(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'CreateTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $request = new PurgeQueueRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PurgeQueue', Queue::class, $optionalArgs, $request)->wait(); } /** - * Deletes a task. + * Resume a queue. * - * A task can be deleted if it is scheduled or dispatched. A task - * cannot be deleted if it has executed successfully or permanently - * failed. + * This method resumes a queue after it has been + * [PAUSED][google.cloud.tasks.v2beta3.Queue.State.PAUSED] or + * [DISABLED][google.cloud.tasks.v2beta3.Queue.State.DISABLED]. The state of a queue is stored + * in the queue's [state][google.cloud.tasks.v2beta3.Queue.state]; after calling this method it + * will be set to [RUNNING][google.cloud.tasks.v2beta3.Queue.State.RUNNING]. + * + * WARNING: Resuming many high-QPS queues at the same time can + * lead to target overloading. If you are resuming high-QPS + * queues, follow the 500/50/5 pattern described in + * [Managing Cloud Tasks Scaling + * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). * * Sample code: * ``` * $cloudTasksClient = new CloudTasksClient(); * try { - * $formattedName = $cloudTasksClient->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - * $cloudTasksClient->deleteTask($formattedName); + * $formattedName = $cloudTasksClient->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + * $response = $cloudTasksClient->resumeQueue($formattedName); * } finally { * $cloudTasksClient->close(); * } * ``` * - * @param string $name Required. The task name. For example: - * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` + * @param string $name Required. The queue name. For example: + * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * + * @return \Google\Cloud\Tasks\V2beta3\Queue + * * @throws ApiException if the remote call fails + * * @experimental */ - public function deleteTask($name, array $optionalArgs = []) + public function resumeQueue($name, array $optionalArgs = []) { - $request = new DeleteTaskRequest(); + $request = new ResumeQueueRequest(); + $requestParamHeaders = []; $request->setName($name); - - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - - return $this->startCall( - 'DeleteTask', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('ResumeQueue', Queue::class, $optionalArgs, $request)->wait(); } /** @@ -1506,54 +1207,231 @@ public function deleteTask($name, array $optionalArgs = []) * @param string $name Required. The task name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` * @param array $optionalArgs { - * Optional. + * Optional. * * @type int $responseView - * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be - * returned. - * - * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all - * information is retrieved by default because some data, such as - * payloads, might be desirable to return only when needed because - * of its large size or because of the sensitivity of data that it - * contains. - * - * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires - * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) - * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. - * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} + * The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be + * returned. + * + * By default response_view is [BASIC][google.cloud.tasks.v2beta3.Task.View.BASIC]; not all + * information is retrieved by default because some data, such as + * payloads, might be desirable to return only when needed because + * of its large size or because of the sensitivity of data that it + * contains. + * + * Authorization for [FULL][google.cloud.tasks.v2beta3.Task.View.FULL] requires + * `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) + * permission on the [Task][google.cloud.tasks.v2beta3.Task] resource. + * For allowed values, use constants defined on {@see \Google\Cloud\Tasks\V2beta3\Task\View} * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a - * {@see Google\ApiCore\RetrySettings} object, or an associative array - * of retry settings parameters. See the documentation on - * {@see Google\ApiCore\RetrySettings} for example usage. + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. * } * * @return \Google\Cloud\Tasks\V2beta3\Task * * @throws ApiException if the remote call fails + * * @experimental */ public function runTask($name, array $optionalArgs = []) { $request = new RunTaskRequest(); + $requestParamHeaders = []; $request->setName($name); + $requestParamHeaders['name'] = $name; if (isset($optionalArgs['responseView'])) { $request->setResponseView($optionalArgs['responseView']); } - $requestParams = new RequestParamsHeaderDescriptor([ - 'name' => $request->getName(), - ]); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('RunTask', Task::class, $optionalArgs, $request)->wait(); + } + + /** + * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta3.Queue]. Replaces any existing + * policy. + * + * Note: The Cloud Console does not check queue-level IAM permissions yet. + * Project-level permissions are required to use the Cloud Console. + * + * Authorization requires the following + * [Google IAM](https://cloud.google.com/iam) permission on the specified + * resource parent: + * + * * `cloudtasks.queues.setIamPolicy` + * + * Sample code: + * ``` + * $cloudTasksClient = new CloudTasksClient(); + * try { + * $resource = 'resource'; + * $policy = new Policy(); + * $response = $cloudTasksClient->setIamPolicy($resource, $policy); + * } finally { + * $cloudTasksClient->close(); + * } + * ``` + * + * @param string $resource REQUIRED: The resource for which the policy is being specified. + * See the operation documentation for the appropriate value for this field. + * @param Policy $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. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Iam\V1\Policy + * + * @throws ApiException if the remote call fails + * + * @experimental + */ + public function setIamPolicy($resource, $policy, array $optionalArgs = []) + { + $request = new SetIamPolicyRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $request->setPolicy($policy); + $requestParamHeaders['resource'] = $resource; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('SetIamPolicy', Policy::class, $optionalArgs, $request)->wait(); + } + + /** + * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta3.Queue]. + * If the resource does not exist, this will return an empty set of + * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. + * + * Note: This operation is designed to be used for building permission-aware + * UIs and command-line tools, not for authorization checking. This operation + * may "fail open" without warning. + * + * Sample code: + * ``` + * $cloudTasksClient = new CloudTasksClient(); + * try { + * $resource = 'resource'; + * $permissions = []; + * $response = $cloudTasksClient->testIamPermissions($resource, $permissions); + * } finally { + * $cloudTasksClient->close(); + * } + * ``` + * + * @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[] $permissions The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse + * + * @throws ApiException if the remote call fails + * + * @experimental + */ + public function testIamPermissions($resource, $permissions, array $optionalArgs = []) + { + $request = new TestIamPermissionsRequest(); + $requestParamHeaders = []; + $request->setResource($resource); + $request->setPermissions($permissions); + $requestParamHeaders['resource'] = $resource; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('TestIamPermissions', TestIamPermissionsResponse::class, $optionalArgs, $request)->wait(); + } + + /** + * Updates a queue. + * + * This method creates the queue if it does not exist and updates + * the queue if it does exist. + * + * Queues created with this method allow tasks to live for a maximum of 31 + * days. After a task is 31 days old, the task will be deleted regardless of whether + * it was dispatched or not. + * + * WARNING: Using this method may have unintended side effects if you are + * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. + * Read + * [Overview of Queue Management and + * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using + * this method. + * + * Sample code: + * ``` + * $cloudTasksClient = new CloudTasksClient(); + * try { + * $queue = new Queue(); + * $response = $cloudTasksClient->updateQueue($queue); + * } finally { + * $cloudTasksClient->close(); + * } + * ``` + * + * @param Queue $queue Required. The queue to create or update. + * + * The queue's [name][google.cloud.tasks.v2beta3.Queue.name] must be specified. + * + * Output only fields cannot be modified using UpdateQueue. + * Any value specified for an output only field will be ignored. + * The queue's [name][google.cloud.tasks.v2beta3.Queue.name] cannot be changed. + * @param array $optionalArgs { + * Optional. + * + * @type FieldMask $updateMask + * A mask used to specify which fields of the queue are being updated. + * + * If empty, then all fields will be updated. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Tasks\V2beta3\Queue + * + * @throws ApiException if the remote call fails + * + * @experimental + */ + public function updateQueue($queue, array $optionalArgs = []) + { + $request = new UpdateQueueRequest(); + $requestParamHeaders = []; + $request->setQueue($queue); + $requestParamHeaders['queue.name'] = $queue->getName(); + if (isset($optionalArgs['updateMask'])) { + $request->setUpdateMask($optionalArgs['updateMask']); + } - return $this->startCall( - 'RunTask', - Task::class, - $optionalArgs, - $request - )->wait(); + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('UpdateQueue', Queue::class, $optionalArgs, $request)->wait(); } } diff --git a/Tasks/src/V2beta3/GetQueueRequest.php b/Tasks/src/V2beta3/GetQueueRequest.php index 1b583b1c0111..90b5ba3c75a3 100644 --- a/Tasks/src/V2beta3/GetQueueRequest.php +++ b/Tasks/src/V2beta3/GetQueueRequest.php @@ -92,7 +92,7 @@ public function setName($var) */ public function getReadMask() { - return isset($this->read_mask) ? $this->read_mask : null; + return $this->read_mask; } public function hasReadMask() diff --git a/Tasks/src/V2beta3/HttpRequest.php b/Tasks/src/V2beta3/HttpRequest.php index 7ef2bf537132..068f45de5ef4 100644 --- a/Tasks/src/V2beta3/HttpRequest.php +++ b/Tasks/src/V2beta3/HttpRequest.php @@ -66,8 +66,8 @@ class HttpRequest extends \Google\Protobuf\Internal\Message * [HttpRequest.url][google.cloud.tasks.v2beta3.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. @@ -119,8 +119,8 @@ class HttpRequest extends \Google\Protobuf\Internal\Message * [HttpRequest.url][google.cloud.tasks.v2beta3.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. @@ -232,8 +232,8 @@ public function setHttpMethod($var) * [HttpRequest.url][google.cloud.tasks.v2beta3.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. @@ -263,8 +263,8 @@ public function getHeaders() * [HttpRequest.url][google.cloud.tasks.v2beta3.HttpRequest.url]. * * Content-Length: This will be computed by Cloud Tasks. * * User-Agent: This will be set to `"Google-Cloud-Tasks"`. - * * X-Google-*: Google use only. - * * X-AppEngine-*: Google use only. + * * `X-Google-*`: Google use only. + * * `X-AppEngine-*`: Google use only. * `Content-Type` won't be set by Cloud Tasks. You can explicitly set * `Content-Type` to a media type when the * [task is created][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. diff --git a/Tasks/src/V2beta3/ListQueuesRequest.php b/Tasks/src/V2beta3/ListQueuesRequest.php index f911a6146b22..84679df60846 100644 --- a/Tasks/src/V2beta3/ListQueuesRequest.php +++ b/Tasks/src/V2beta3/ListQueuesRequest.php @@ -270,7 +270,7 @@ public function setPageToken($var) */ public function getReadMask() { - return isset($this->read_mask) ? $this->read_mask : null; + return $this->read_mask; } public function hasReadMask() diff --git a/Tasks/src/V2beta3/Queue.php b/Tasks/src/V2beta3/Queue.php index a25350e4510e..ae67bfaac172 100644 --- a/Tasks/src/V2beta3/Queue.php +++ b/Tasks/src/V2beta3/Queue.php @@ -79,7 +79,7 @@ class Queue extends \Google\Protobuf\Internal\Message private $retry_config = null; /** * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta3.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -216,7 +216,7 @@ class Queue extends \Google\Protobuf\Internal\Message * documentation](https://cloud.google.com/appengine/docs/standard/python/taskqueue/push/retrying-tasks). * @type int $state * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta3.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -388,7 +388,7 @@ public function setAppEngineHttpQueue($var) */ public function getRateLimits() { - return isset($this->rate_limits) ? $this->rate_limits : null; + return $this->rate_limits; } public function hasRateLimits() @@ -451,7 +451,7 @@ public function setRateLimits($var) */ public function getRetryConfig() { - return isset($this->retry_config) ? $this->retry_config : null; + return $this->retry_config; } public function hasRetryConfig() @@ -489,7 +489,7 @@ public function setRetryConfig($var) /** * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta3.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -505,7 +505,7 @@ public function getState() /** * Output only. The state of the queue. - * `state` can only be changed by called + * `state` can only be changed by calling * [PauseQueue][google.cloud.tasks.v2beta3.CloudTasks.PauseQueue], * [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue], or uploading * [queue.yaml/xml](https://cloud.google.com/appengine/docs/python/config/queueref). @@ -538,7 +538,7 @@ public function setState($var) */ public function getPurgeTime() { - return isset($this->purge_time) ? $this->purge_time : null; + return $this->purge_time; } public function hasPurgeTime() @@ -590,7 +590,7 @@ public function setPurgeTime($var) */ public function getTaskTtl() { - return isset($this->task_ttl) ? $this->task_ttl : null; + return $this->task_ttl; } public function hasTaskTtl() @@ -642,7 +642,7 @@ public function setTaskTtl($var) */ public function getTombstoneTtl() { - return isset($this->tombstone_ttl) ? $this->tombstone_ttl : null; + return $this->tombstone_ttl; } public function hasTombstoneTtl() @@ -687,7 +687,7 @@ public function setTombstoneTtl($var) */ public function getStackdriverLoggingConfig() { - return isset($this->stackdriver_logging_config) ? $this->stackdriver_logging_config : null; + return $this->stackdriver_logging_config; } public function hasStackdriverLoggingConfig() @@ -759,7 +759,7 @@ public function setType($var) */ public function getStats() { - return isset($this->stats) ? $this->stats : null; + return $this->stats; } public function hasStats() diff --git a/Tasks/src/V2beta3/QueueStats.php b/Tasks/src/V2beta3/QueueStats.php index 398dd3cf7db4..d6a3e5dc1df1 100644 --- a/Tasks/src/V2beta3/QueueStats.php +++ b/Tasks/src/V2beta3/QueueStats.php @@ -130,7 +130,7 @@ public function setTasksCount($var) */ public function getOldestEstimatedArrivalTime() { - return isset($this->oldest_estimated_arrival_time) ? $this->oldest_estimated_arrival_time : null; + return $this->oldest_estimated_arrival_time; } public function hasOldestEstimatedArrivalTime() diff --git a/Tasks/src/V2beta3/RetryConfig.php b/Tasks/src/V2beta3/RetryConfig.php index 55de2e237d04..2af9eb9ad617 100644 --- a/Tasks/src/V2beta3/RetryConfig.php +++ b/Tasks/src/V2beta3/RetryConfig.php @@ -256,7 +256,7 @@ public function setMaxAttempts($var) */ public function getMaxRetryDuration() { - return isset($this->max_retry_duration) ? $this->max_retry_duration : null; + return $this->max_retry_duration; } public function hasMaxRetryDuration() @@ -314,7 +314,7 @@ public function setMaxRetryDuration($var) */ public function getMinBackoff() { - return isset($this->min_backoff) ? $this->min_backoff : null; + return $this->min_backoff; } public function hasMinBackoff() @@ -370,7 +370,7 @@ public function setMinBackoff($var) */ public function getMaxBackoff() { - return isset($this->max_backoff) ? $this->max_backoff : null; + return $this->max_backoff; } public function hasMaxBackoff() diff --git a/Tasks/src/V2beta3/Task.php b/Tasks/src/V2beta3/Task.php index 8c8333cbc739..bca0ae44199d 100644 --- a/Tasks/src/V2beta3/Task.php +++ b/Tasks/src/V2beta3/Task.php @@ -391,7 +391,7 @@ public function setPullMessage($var) */ public function getScheduleTime() { - return isset($this->schedule_time) ? $this->schedule_time : null; + return $this->schedule_time; } public function hasScheduleTime() @@ -430,7 +430,7 @@ public function setScheduleTime($var) */ public function getCreateTime() { - return isset($this->create_time) ? $this->create_time : null; + return $this->create_time; } public function hasCreateTime() @@ -492,7 +492,7 @@ public function setCreateTime($var) */ public function getDispatchDeadline() { - return isset($this->dispatch_deadline) ? $this->dispatch_deadline : null; + return $this->dispatch_deadline; } public function hasDispatchDeadline() @@ -611,7 +611,7 @@ public function setResponseCount($var) */ public function getFirstAttempt() { - return isset($this->first_attempt) ? $this->first_attempt : null; + return $this->first_attempt; } public function hasFirstAttempt() @@ -649,7 +649,7 @@ public function setFirstAttempt($var) */ public function getLastAttempt() { - return isset($this->last_attempt) ? $this->last_attempt : null; + return $this->last_attempt; } public function hasLastAttempt() diff --git a/Tasks/src/V2beta3/UpdateQueueRequest.php b/Tasks/src/V2beta3/UpdateQueueRequest.php index 4c06b708f688..109f7ab308ff 100644 --- a/Tasks/src/V2beta3/UpdateQueueRequest.php +++ b/Tasks/src/V2beta3/UpdateQueueRequest.php @@ -67,7 +67,7 @@ public function __construct($data = NULL) { */ public function getQueue() { - return isset($this->queue) ? $this->queue : null; + return $this->queue; } public function hasQueue() @@ -108,7 +108,7 @@ public function setQueue($var) */ public function getUpdateMask() { - return isset($this->update_mask) ? $this->update_mask : null; + return $this->update_mask; } public function hasUpdateMask() diff --git a/Tasks/src/V2beta3/gapic_metadata.json b/Tasks/src/V2beta3/gapic_metadata.json new file mode 100644 index 000000000000..61b5c721a665 --- /dev/null +++ b/Tasks/src/V2beta3/gapic_metadata.json @@ -0,0 +1,98 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services\/RPCs to the corresponding library clients\/methods", + "language": "php", + "protoPackage": "google.cloud.tasks.v2beta3", + "libraryPackage": "Google\\Cloud\\Tasks\\V2beta3", + "services": { + "CloudTasks": { + "clients": { + "grpc": { + "libraryClient": "CloudTasksGapicClient", + "rpcs": { + "CreateQueue": { + "methods": [ + "createQueue" + ] + }, + "CreateTask": { + "methods": [ + "createTask" + ] + }, + "DeleteQueue": { + "methods": [ + "deleteQueue" + ] + }, + "DeleteTask": { + "methods": [ + "deleteTask" + ] + }, + "GetIamPolicy": { + "methods": [ + "getIamPolicy" + ] + }, + "GetQueue": { + "methods": [ + "getQueue" + ] + }, + "GetTask": { + "methods": [ + "getTask" + ] + }, + "ListQueues": { + "methods": [ + "listQueues" + ] + }, + "ListTasks": { + "methods": [ + "listTasks" + ] + }, + "PauseQueue": { + "methods": [ + "pauseQueue" + ] + }, + "PurgeQueue": { + "methods": [ + "purgeQueue" + ] + }, + "ResumeQueue": { + "methods": [ + "resumeQueue" + ] + }, + "RunTask": { + "methods": [ + "runTask" + ] + }, + "SetIamPolicy": { + "methods": [ + "setIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "testIamPermissions" + ] + }, + "UpdateQueue": { + "methods": [ + "updateQueue" + ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Tasks/src/V2beta3/resources/cloud_tasks_client_config.json b/Tasks/src/V2beta3/resources/cloud_tasks_client_config.json index c535acea0801..99bdac739d33 100644 --- a/Tasks/src/V2beta3/resources/cloud_tasks_client_config.json +++ b/Tasks/src/V2beta3/resources/cloud_tasks_client_config.json @@ -1,125 +1,125 @@ { - "interfaces": { - "google.cloud.tasks.v2beta3.CloudTasks": { - "retry_codes": { - "retry_policy_1_codes": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "no_retry_codes": [], - "no_retry_1_codes": [] - }, - "retry_params": { - "retry_policy_1_params": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 10000, - "initial_rpc_timeout_millis": 20000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 20000, - "total_timeout_millis": 20000 - }, - "no_retry_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 0, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 0, - "total_timeout_millis": 0 - }, - "no_retry_1_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 20000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 20000, - "total_timeout_millis": 20000 + "interfaces": { + "google.cloud.tasks.v2beta3.CloudTasks": { + "retry_codes": { + "no_retry_codes": [], + "no_retry_1_codes": [], + "retry_policy_1_codes": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "no_retry_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 0, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 0, + "total_timeout_millis": 0 + }, + "no_retry_1_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 20000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 20000, + "total_timeout_millis": 20000 + }, + "retry_policy_1_params": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 10000, + "initial_rpc_timeout_millis": 20000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 20000, + "total_timeout_millis": 20000 + } + }, + "methods": { + "CreateQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "CreateTask": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "DeleteQueue": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "DeleteTask": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetIamPolicy": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetQueue": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetTask": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListQueues": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListTasks": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "PauseQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "PurgeQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "ResumeQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "RunTask": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "SetIamPolicy": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "TestIamPermissions": { + "timeout_millis": 20000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "UpdateQueue": { + "timeout_millis": 20000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + } + } } - }, - "methods": { - "ListQueues": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "GetQueue": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "CreateQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "UpdateQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "DeleteQueue": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "PurgeQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "PauseQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "ResumeQueue": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "GetIamPolicy": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "SetIamPolicy": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "TestIamPermissions": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "ListTasks": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "GetTask": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "CreateTask": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - }, - "DeleteTask": { - "timeout_millis": 20000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params" - }, - "RunTask": { - "timeout_millis": 20000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params" - } - } } - } } diff --git a/Tasks/src/V2beta3/resources/cloud_tasks_rest_client_config.php b/Tasks/src/V2beta3/resources/cloud_tasks_rest_client_config.php index 41368ea52675..608534c564a3 100644 --- a/Tasks/src/V2beta3/resources/cloud_tasks_rest_client_config.php +++ b/Tasks/src/V2beta3/resources/cloud_tasks_rest_client_config.php @@ -3,9 +3,10 @@ return [ 'interfaces' => [ 'google.cloud.tasks.v2beta3.CloudTasks' => [ - 'ListQueues' => [ - 'method' => 'get', + 'CreateQueue' => [ + 'method' => 'post', 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*}/queues', + 'body' => 'queue', 'placeholders' => [ 'parent' => [ 'getters' => [ @@ -14,21 +15,10 @@ ], ], ], - 'GetQueue' => [ - 'method' => 'get', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], - 'CreateQueue' => [ + 'CreateTask' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*}/queues', - 'body' => 'queue', + 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*/queues/*}/tasks', + 'body' => '*', 'placeholders' => [ 'parent' => [ 'getters' => [ @@ -37,22 +27,20 @@ ], ], ], - 'UpdateQueue' => [ - 'method' => 'patch', - 'uriTemplate' => '/v2beta3/{queue.name=projects/*/locations/*/queues/*}', - 'body' => 'queue', + 'DeleteQueue' => [ + 'method' => 'delete', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}', 'placeholders' => [ - 'queue.name' => [ + 'name' => [ 'getters' => [ - 'getQueue', 'getName', ], ], ], ], - 'DeleteQueue' => [ + 'DeleteTask' => [ 'method' => 'delete', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -61,22 +49,21 @@ ], ], ], - 'PurgeQueue' => [ + 'GetIamPolicy' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}:purge', + 'uriTemplate' => '/v2beta3/{resource=projects/*/locations/*/queues/*}:getIamPolicy', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'PauseQueue' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}:pause', - 'body' => '*', + 'GetQueue' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -85,10 +72,9 @@ ], ], ], - 'ResumeQueue' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}:resume', - 'body' => '*', + 'GetTask' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -97,56 +83,56 @@ ], ], ], - 'GetIamPolicy' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta3/{resource=projects/*/locations/*/queues/*}:getIamPolicy', - 'body' => '*', + 'ListQueues' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*}/queues', 'placeholders' => [ - 'resource' => [ + 'parent' => [ 'getters' => [ - 'getResource', + 'getParent', ], ], ], ], - 'SetIamPolicy' => [ - 'method' => 'post', - 'uriTemplate' => '/v2beta3/{resource=projects/*/locations/*/queues/*}:setIamPolicy', - 'body' => '*', + 'ListTasks' => [ + 'method' => 'get', + 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*/queues/*}/tasks', 'placeholders' => [ - 'resource' => [ + 'parent' => [ 'getters' => [ - 'getResource', + 'getParent', ], ], ], ], - 'TestIamPermissions' => [ + 'PauseQueue' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta3/{resource=projects/*/locations/*/queues/*}:testIamPermissions', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}:pause', 'body' => '*', 'placeholders' => [ - 'resource' => [ + 'name' => [ 'getters' => [ - 'getResource', + 'getName', ], ], ], ], - 'ListTasks' => [ - 'method' => 'get', - 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*/queues/*}/tasks', + 'PurgeQueue' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}:purge', + 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'GetTask' => [ - 'method' => 'get', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}', + 'ResumeQueue' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*}:resume', + 'body' => '*', 'placeholders' => [ 'name' => [ 'getters' => [ @@ -155,36 +141,50 @@ ], ], ], - 'CreateTask' => [ + 'RunTask' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta3/{parent=projects/*/locations/*/queues/*}/tasks', + 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}:run', 'body' => '*', 'placeholders' => [ - 'parent' => [ + 'name' => [ 'getters' => [ - 'getParent', + 'getName', ], ], ], ], - 'DeleteTask' => [ - 'method' => 'delete', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}', + 'SetIamPolicy' => [ + 'method' => 'post', + 'uriTemplate' => '/v2beta3/{resource=projects/*/locations/*/queues/*}:setIamPolicy', + 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ 'getters' => [ - 'getName', + 'getResource', ], ], ], ], - 'RunTask' => [ + 'TestIamPermissions' => [ 'method' => 'post', - 'uriTemplate' => '/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}:run', + 'uriTemplate' => '/v2beta3/{resource=projects/*/locations/*/queues/*}:testIamPermissions', 'body' => '*', 'placeholders' => [ - 'name' => [ + 'resource' => [ + 'getters' => [ + 'getResource', + ], + ], + ], + ], + 'UpdateQueue' => [ + 'method' => 'patch', + 'uriTemplate' => '/v2beta3/{queue.name=projects/*/locations/*/queues/*}', + 'body' => 'queue', + 'placeholders' => [ + 'queue.name' => [ 'getters' => [ + 'getQueue', 'getName', ], ], diff --git a/Tasks/tests/Unit/V2/CloudTasksClientTest.php b/Tasks/tests/Unit/V2/CloudTasksClientTest.php index 012da6becb96..7ff127931198 100644 --- a/Tasks/tests/Unit/V2/CloudTasksClientTest.php +++ b/Tasks/tests/Unit/V2/CloudTasksClientTest.php @@ -22,24 +22,26 @@ namespace Google\Cloud\Tasks\Tests\Unit\V2; -use Google\Cloud\Tasks\V2\CloudTasksClient; use Google\ApiCore\ApiException; + use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\Testing\GeneratedTest; use Google\ApiCore\Testing\MockTransport; + use Google\Cloud\Iam\V1\Policy; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; +use Google\Cloud\Tasks\V2\CloudTasksClient; use Google\Cloud\Tasks\V2\ListQueuesResponse; use Google\Cloud\Tasks\V2\ListTasksResponse; use Google\Cloud\Tasks\V2\Queue; use Google\Cloud\Tasks\V2\Task; -use Google\Protobuf\Any; use Google\Protobuf\GPBEmpty; use Google\Rpc\Code; use stdClass; /** * @group tasks + * * @group gapic */ class CloudTasksClientTest extends GeneratedTest @@ -57,9 +59,7 @@ private function createTransport($deserialize = null) */ private function createCredentials() { - return $this->getMockBuilder(CredentialsWrapper::class) - ->disableOriginalConstructor() - ->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); } /** @@ -70,84 +70,72 @@ private function createClient(array $options = []) $options += [ 'credentials' => $this->createCredentials(), ]; - return new CloudTasksClient($options); } /** * @test */ - public function listQueuesTest() + public function createQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $queuesElement = new Queue(); - $queues = [$queuesElement]; - $expectedResponse = new ListQueuesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setQueues($queues); + $name = 'name3373707'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - - $response = $client->listQueues($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getQueues()[0], $resources[0]); - + $queue = new Queue(); + $response = $client->createQueue($formattedParent, $queue); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/ListQueues', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/CreateQueue', $actualFuncCall); $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getQueue(); + $this->assertProtobufEquals($queue, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function listQueuesExceptionTest() + public function createQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - + $queue = new Queue(); try { - $client->listQueues($formattedParent); + $client->createQueue($formattedParent, $queue); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -156,71 +144,70 @@ public function listQueuesExceptionTest() /** * @test */ - public function getQueueTest() + public function createTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name2); + $name = 'name3373707'; + $dispatchCount = 1217252086; + $responseCount = 424727441; + $expectedResponse = new Task(); + $expectedResponse->setName($name); + $expectedResponse->setDispatchCount($dispatchCount); + $expectedResponse->setResponseCount($responseCount); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->getQueue($formattedName); + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $task = new Task(); + $response = $client->createTask($formattedParent, $task); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/GetQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/CreateTask', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getTask(); + $this->assertProtobufEquals($task, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getQueueExceptionTest() + public function createTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $task = new Task(); try { - $client->getQueue($formattedName); + $client->createTask($formattedParent, $task); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -229,76 +216,59 @@ public function getQueueExceptionTest() /** * @test */ - public function createQueueTest() + public function deleteQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name); + $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - $queue = new Queue(); - - $response = $client->createQueue($formattedParent, $queue); - $this->assertEquals($expectedResponse, $response); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $client->deleteQueue($formattedName); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/CreateQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getQueue(); - - $this->assertProtobufEquals($queue, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/DeleteQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function createQueueExceptionTest() + public function deleteQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - $queue = new Queue(); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->createQueue($formattedParent, $queue); + $client->deleteQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -307,71 +277,59 @@ public function createQueueExceptionTest() /** * @test */ - public function updateQueueTest() + public function deleteTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name); + $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request - $queue = new Queue(); - - $response = $client->updateQueue($queue); - $this->assertEquals($expectedResponse, $response); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $client->deleteTask($formattedName); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/UpdateQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getQueue(); - - $this->assertProtobufEquals($queue, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/DeleteTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function updateQueueExceptionTest() + public function deleteTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $queue = new Queue(); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); try { - $client->updateQueue($queue); + $client->deleteTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -380,68 +338,64 @@ public function updateQueueExceptionTest() /** * @test */ - public function deleteQueueTest() + public function getIamPolicyTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $client->deleteQueue($formattedName); + $resource = 'resource-341064690'; + $response = $client->getIamPolicy($resource); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/DeleteQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function deleteQueueExceptionTest() + public function getIamPolicyExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $resource = 'resource-341064690'; try { - $client->deleteQueue($formattedName); + $client->getIamPolicy($resource); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -450,71 +404,62 @@ public function deleteQueueExceptionTest() /** * @test */ - public function purgeQueueTest() + public function getQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; $expectedResponse = new Queue(); $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->purgeQueue($formattedName); + $response = $client->getQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/PurgeQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/GetQueue', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function purgeQueueExceptionTest() + public function getQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - try { - $client->purgeQueue($formattedName); + $client->getQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -523,71 +468,66 @@ public function purgeQueueExceptionTest() /** * @test */ - public function pauseQueueTest() + public function getTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); + $dispatchCount = 1217252086; + $responseCount = 424727441; + $expectedResponse = new Task(); $expectedResponse->setName($name2); + $expectedResponse->setDispatchCount($dispatchCount); + $expectedResponse->setResponseCount($responseCount); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->pauseQueue($formattedName); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $response = $client->getTask($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/PauseQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/GetTask', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function pauseQueueExceptionTest() + public function getTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); try { - $client->pauseQueue($formattedName); + $client->getTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -596,71 +536,70 @@ public function pauseQueueExceptionTest() /** * @test */ - public function resumeQueueTest() + public function listQueuesTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name2); + $nextPageToken = ''; + $queuesElement = new Queue(); + $queues = [ + $queuesElement, + ]; + $expectedResponse = new ListQueuesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setQueues($queues); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->resumeQueue($formattedName); - $this->assertEquals($expectedResponse, $response); + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); + $response = $client->listQueues($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getQueues()[0], $resources[0]); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/ResumeQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/ListQueues', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function resumeQueueExceptionTest() + public function listQueuesExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); try { - $client->resumeQueue($formattedName); + $client->listQueues($formattedParent); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -669,73 +608,70 @@ public function resumeQueueExceptionTest() /** * @test */ - public function getIamPolicyTest() + public function listTasksTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); + $nextPageToken = ''; + $tasksElement = new Task(); + $tasks = [ + $tasksElement, + ]; + $expectedResponse = new ListTasksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTasks($tasks); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - - $response = $client->getIamPolicy($resource); - $this->assertEquals($expectedResponse, $response); + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->listTasks($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/GetIamPolicy', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/ListTasks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getIamPolicyExceptionTest() + public function listTasksExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->getIamPolicy($resource); + $client->listTasks($formattedParent); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -744,78 +680,62 @@ public function getIamPolicyExceptionTest() /** * @test */ - public function setIamPolicyTest() + public function pauseQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - - $response = $client->setIamPolicy($resource, $policy); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->pauseQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/SetIamPolicy', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPolicy(); - - $this->assertProtobufEquals($policy, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/PauseQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function setIamPolicyExceptionTest() + public function pauseQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->setIamPolicy($resource, $policy); + $client->pauseQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -824,74 +744,62 @@ public function setIamPolicyExceptionTest() /** * @test */ - public function testIamPermissionsTest() + public function purgeQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new TestIamPermissionsResponse(); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - - $response = $client->testIamPermissions($resource, $permissions); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->purgeQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/TestIamPermissions', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPermissions(); - - $this->assertProtobufEquals($permissions, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/PurgeQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function testIamPermissionsExceptionTest() + public function purgeQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->testIamPermissions($resource, $permissions); + $client->purgeQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -900,77 +808,62 @@ public function testIamPermissionsExceptionTest() /** * @test */ - public function listTasksTest() + public function resumeQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $tasksElement = new Task(); - $tasks = [$tasksElement]; - $expectedResponse = new ListTasksResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setTasks($tasks); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->listTasks($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->resumeQueue($formattedName); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/ListTasks', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/ResumeQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function listTasksExceptionTest() + public function resumeQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->listTasks($formattedParent); + $client->resumeQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -979,13 +872,13 @@ public function listTasksExceptionTest() /** * @test */ - public function getTaskTest() + public function runTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; $dispatchCount = 1217252086; @@ -995,59 +888,50 @@ public function getTaskTest() $expectedResponse->setDispatchCount($dispatchCount); $expectedResponse->setResponseCount($responseCount); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $response = $client->getTask($formattedName); + $response = $client->runTask($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/GetTask', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/RunTask', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getTaskExceptionTest() + public function runTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - try { - $client->getTask($formattedName); + $client->runTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1056,80 +940,68 @@ public function getTaskExceptionTest() /** * @test */ - public function createTaskTest() + public function setIamPolicyTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $dispatchCount = 1217252086; - $responseCount = 424727441; - $expectedResponse = new Task(); - $expectedResponse->setName($name); - $expectedResponse->setDispatchCount($dispatchCount); - $expectedResponse->setResponseCount($responseCount); + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $task = new Task(); - - $response = $client->createTask($formattedParent, $task); + $resource = 'resource-341064690'; + $policy = new Policy(); + $response = $client->setIamPolicy($resource, $policy); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/CreateTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getTask(); - - $this->assertProtobufEquals($task, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function createTaskExceptionTest() + public function setIamPolicyExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $task = new Task(); - + $resource = 'resource-341064690'; + $policy = new Policy(); try { - $client->createTask($formattedParent, $task); + $client->setIamPolicy($resource, $policy); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1138,68 +1010,64 @@ public function createTaskExceptionTest() /** * @test */ - public function deleteTaskTest() + public function testIamPermissionsTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); + $expectedResponse = new TestIamPermissionsResponse(); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $client->deleteTask($formattedName); + $resource = 'resource-341064690'; + $permissions = []; + $response = $client->testIamPermissions($resource, $permissions); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/DeleteTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function deleteTaskExceptionTest() + public function testIamPermissionsExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $resource = 'resource-341064690'; + $permissions = []; try { - $client->deleteTask($formattedName); + $client->testIamPermissions($resource, $permissions); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1208,75 +1076,62 @@ public function deleteTaskExceptionTest() /** * @test */ - public function runTaskTest() + public function updateQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $dispatchCount = 1217252086; - $responseCount = 424727441; - $expectedResponse = new Task(); - $expectedResponse->setName($name2); - $expectedResponse->setDispatchCount($dispatchCount); - $expectedResponse->setResponseCount($responseCount); + $name = 'name3373707'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $response = $client->runTask($formattedName); + $queue = new Queue(); + $response = $client->updateQueue($queue); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2.CloudTasks/RunTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2.CloudTasks/UpdateQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getQueue(); + $this->assertProtobufEquals($queue, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function runTaskExceptionTest() + public function updateQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $queue = new Queue(); try { - $client->runTask($formattedName); + $client->updateQueue($queue); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); diff --git a/Tasks/tests/Unit/V2beta2/CloudTasksClientTest.php b/Tasks/tests/Unit/V2beta2/CloudTasksClientTest.php index 112e6b1efca3..64e96151de86 100644 --- a/Tasks/tests/Unit/V2beta2/CloudTasksClientTest.php +++ b/Tasks/tests/Unit/V2beta2/CloudTasksClientTest.php @@ -22,19 +22,20 @@ namespace Google\Cloud\Tasks\Tests\Unit\V2beta2; -use Google\Cloud\Tasks\V2beta2\CloudTasksClient; use Google\ApiCore\ApiException; + use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\Testing\GeneratedTest; use Google\ApiCore\Testing\MockTransport; + use Google\Cloud\Iam\V1\Policy; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; +use Google\Cloud\Tasks\V2beta2\CloudTasksClient; use Google\Cloud\Tasks\V2beta2\LeaseTasksResponse; use Google\Cloud\Tasks\V2beta2\ListQueuesResponse; use Google\Cloud\Tasks\V2beta2\ListTasksResponse; use Google\Cloud\Tasks\V2beta2\Queue; use Google\Cloud\Tasks\V2beta2\Task; -use Google\Protobuf\Any; use Google\Protobuf\Duration; use Google\Protobuf\GPBEmpty; use Google\Protobuf\Timestamp; @@ -43,6 +44,7 @@ /** * @group tasks + * * @group gapic */ class CloudTasksClientTest extends GeneratedTest @@ -60,9 +62,7 @@ private function createTransport($deserialize = null) */ private function createCredentials() { - return $this->getMockBuilder(CredentialsWrapper::class) - ->disableOriginalConstructor() - ->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); } /** @@ -73,84 +73,69 @@ private function createClient(array $options = []) $options += [ 'credentials' => $this->createCredentials(), ]; - return new CloudTasksClient($options); } /** * @test */ - public function listQueuesTest() + public function acknowledgeTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $queuesElement = new Queue(); - $queues = [$queuesElement]; - $expectedResponse = new ListQueuesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setQueues($queues); + $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - - $response = $client->listQueues($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getQueues()[0], $resources[0]); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $scheduleTime = new Timestamp(); + $client->acknowledgeTask($formattedName, $scheduleTime); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/ListQueues', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/AcknowledgeTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getScheduleTime(); + $this->assertProtobufEquals($scheduleTime, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function listQueuesExceptionTest() + public function acknowledgeTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $scheduleTime = new Timestamp(); try { - $client->listQueues($formattedParent); + $client->acknowledgeTask($formattedName, $scheduleTime); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -159,71 +144,66 @@ public function listQueuesExceptionTest() /** * @test */ - public function getQueueTest() + public function cancelLeaseTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); + $expectedResponse = new Task(); $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->getQueue($formattedName); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $scheduleTime = new Timestamp(); + $response = $client->cancelLease($formattedName, $scheduleTime); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/GetQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/CancelLease', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - + $actualValue = $actualRequestObject->getScheduleTime(); + $this->assertProtobufEquals($scheduleTime, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getQueueExceptionTest() + public function cancelLeaseExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $scheduleTime = new Timestamp(); try { - $client->getQueue($formattedName); + $client->cancelLease($formattedName, $scheduleTime); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -235,20 +215,18 @@ public function getQueueExceptionTest() public function createQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name = 'name3373707'; $expectedResponse = new Queue(); $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); $queue = new Queue(); - $response = $client->createQueue($formattedParent, $queue); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -256,14 +234,10 @@ public function createQueueTest() $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/CreateQueue', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); $actualValue = $actualRequestObject->getQueue(); - $this->assertProtobufEquals($queue, $actualValue); - $this->assertTrue($transport->isExhausted()); } @@ -273,26 +247,23 @@ public function createQueueTest() public function createQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); $queue = new Queue(); - try { $client->createQueue($formattedParent, $queue); // If the $client method call did not throw, fail the test @@ -301,7 +272,6 @@ public function createQueueExceptionTest() $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -310,71 +280,66 @@ public function createQueueExceptionTest() /** * @test */ - public function updateQueueTest() + public function createTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name = 'name3373707'; - $expectedResponse = new Queue(); + $expectedResponse = new Task(); $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request - $queue = new Queue(); - - $response = $client->updateQueue($queue); + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $task = new Task(); + $response = $client->createTask($formattedParent, $task); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/UpdateQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getQueue(); - - $this->assertProtobufEquals($queue, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/CreateTask', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getTask(); + $this->assertProtobufEquals($task, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function updateQueueExceptionTest() + public function createTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $queue = new Queue(); - + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $task = new Task(); try { - $client->updateQueue($queue); + $client->createTask($formattedParent, $task); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -386,28 +351,23 @@ public function updateQueueExceptionTest() public function deleteQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $client->deleteQueue($formattedName); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/DeleteQueue', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } @@ -417,25 +377,22 @@ public function deleteQueueTest() public function deleteQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - try { $client->deleteQueue($formattedName); // If the $client method call did not throw, fail the test @@ -444,7 +401,6 @@ public function deleteQueueExceptionTest() $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -453,71 +409,59 @@ public function deleteQueueExceptionTest() /** * @test */ - public function purgeQueueTest() + public function deleteTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name2); + $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->purgeQueue($formattedName); - $this->assertEquals($expectedResponse, $response); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $client->deleteTask($formattedName); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/PurgeQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/DeleteTask', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function purgeQueueExceptionTest() + public function deleteTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); try { - $client->purgeQueue($formattedName); + $client->deleteTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -526,71 +470,64 @@ public function purgeQueueExceptionTest() /** * @test */ - public function pauseQueueTest() + public function getIamPolicyTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name2); + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->pauseQueue($formattedName); + $resource = 'resource-341064690'; + $response = $client->getIamPolicy($resource); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/PauseQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function pauseQueueExceptionTest() + public function getIamPolicyExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $resource = 'resource-341064690'; try { - $client->pauseQueue($formattedName); + $client->getIamPolicy($resource); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -599,71 +536,62 @@ public function pauseQueueExceptionTest() /** * @test */ - public function resumeQueueTest() + public function getQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; $expectedResponse = new Queue(); $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->resumeQueue($formattedName); + $response = $client->getQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/ResumeQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/GetQueue', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function resumeQueueExceptionTest() + public function getQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - try { - $client->resumeQueue($formattedName); + $client->getQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -672,73 +600,62 @@ public function resumeQueueExceptionTest() /** * @test */ - public function getIamPolicyTest() + public function getTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); + $name2 = 'name2-1052831874'; + $expectedResponse = new Task(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - - $response = $client->getIamPolicy($resource); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $response = $client->getTask($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/GetIamPolicy', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/GetTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getIamPolicyExceptionTest() + public function getTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); try { - $client->getIamPolicy($resource); + $client->getTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -747,78 +664,64 @@ public function getIamPolicyExceptionTest() /** * @test */ - public function setIamPolicyTest() + public function leaseTasksTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); + $expectedResponse = new LeaseTasksResponse(); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - - $response = $client->setIamPolicy($resource, $policy); + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $leaseDuration = new Duration(); + $response = $client->leaseTasks($formattedParent, $leaseDuration); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/SetIamPolicy', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPolicy(); - - $this->assertProtobufEquals($policy, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/LeaseTasks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getLeaseDuration(); + $this->assertProtobufEquals($leaseDuration, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function setIamPolicyExceptionTest() + public function leaseTasksExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $leaseDuration = new Duration(); try { - $client->setIamPolicy($resource, $policy); + $client->leaseTasks($formattedParent, $leaseDuration); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -827,74 +730,70 @@ public function setIamPolicyExceptionTest() /** * @test */ - public function testIamPermissionsTest() + public function listQueuesTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new TestIamPermissionsResponse(); + $nextPageToken = ''; + $queuesElement = new Queue(); + $queues = [ + $queuesElement, + ]; + $expectedResponse = new ListQueuesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setQueues($queues); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - - $response = $client->testIamPermissions($resource, $permissions); - $this->assertEquals($expectedResponse, $response); + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); + $response = $client->listQueues($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getQueues()[0], $resources[0]); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/TestIamPermissions', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPermissions(); - - $this->assertProtobufEquals($permissions, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/ListQueues', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function testIamPermissionsExceptionTest() + public function listQueuesExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); try { - $client->testIamPermissions($resource, $permissions); + $client->listQueues($formattedParent); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -906,36 +805,33 @@ public function testIamPermissionsExceptionTest() public function listTasksTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $nextPageToken = ''; $tasksElement = new Task(); - $tasks = [$tasksElement]; + $tasks = [ + $tasksElement, + ]; $expectedResponse = new ListTasksResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setTasks($tasks); $transport->addResponse($expectedResponse); - // Mock request $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $response = $client->listTasks($formattedParent); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); $this->assertSame(1, count($resources)); $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/ListTasks', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); } @@ -946,25 +842,22 @@ public function listTasksTest() public function listTasksExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - try { $client->listTasks($formattedParent); // If the $client method call did not throw, fail the test @@ -973,7 +866,6 @@ public function listTasksExceptionTest() $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -982,71 +874,62 @@ public function listTasksExceptionTest() /** * @test */ - public function getTaskTest() + public function pauseQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; - $expectedResponse = new Task(); + $expectedResponse = new Queue(); $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $response = $client->getTask($formattedName); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->pauseQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/GetTask', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/PauseQueue', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getTaskExceptionTest() + public function pauseQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->getTask($formattedName); + $client->pauseQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1055,76 +938,62 @@ public function getTaskExceptionTest() /** * @test */ - public function createTaskTest() + public function purgeQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $expectedResponse = new Task(); - $expectedResponse->setName($name); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $task = new Task(); - - $response = $client->createTask($formattedParent, $task); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->purgeQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/CreateTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getTask(); - - $this->assertProtobufEquals($task, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/PurgeQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function createTaskExceptionTest() + public function purgeQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $task = new Task(); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->createTask($formattedParent, $task); + $client->purgeQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1133,68 +1002,70 @@ public function createTaskExceptionTest() /** * @test */ - public function deleteTaskTest() + public function renewLeaseTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); + $name2 = 'name2-1052831874'; + $expectedResponse = new Task(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $client->deleteTask($formattedName); + $scheduleTime = new Timestamp(); + $leaseDuration = new Duration(); + $response = $client->renewLease($formattedName, $scheduleTime, $leaseDuration); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/DeleteTask', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/RenewLease', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - + $actualValue = $actualRequestObject->getScheduleTime(); + $this->assertProtobufEquals($scheduleTime, $actualValue); + $actualValue = $actualRequestObject->getLeaseDuration(); + $this->assertProtobufEquals($leaseDuration, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function deleteTaskExceptionTest() + public function renewLeaseExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $scheduleTime = new Timestamp(); + $leaseDuration = new Duration(); try { - $client->deleteTask($formattedName); + $client->renewLease($formattedName, $scheduleTime, $leaseDuration); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1203,74 +1074,62 @@ public function deleteTaskExceptionTest() /** * @test */ - public function leaseTasksTest() + public function resumeQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new LeaseTasksResponse(); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $leaseDuration = new Duration(); - - $response = $client->leaseTasks($formattedParent, $leaseDuration); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->resumeQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/LeaseTasks', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getLeaseDuration(); - - $this->assertProtobufEquals($leaseDuration, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/ResumeQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function leaseTasksExceptionTest() + public function resumeQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $leaseDuration = new Duration(); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->leaseTasks($formattedParent, $leaseDuration); + $client->resumeQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1279,73 +1138,62 @@ public function leaseTasksExceptionTest() /** * @test */ - public function acknowledgeTaskTest() + public function runTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); + $name2 = 'name2-1052831874'; + $expectedResponse = new Task(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - $scheduleTime = new Timestamp(); - - $client->acknowledgeTask($formattedName, $scheduleTime); + $response = $client->runTask($formattedName); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/AcknowledgeTask', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/RunTask', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $actualValue = $actualRequestObject->getScheduleTime(); - - $this->assertProtobufEquals($scheduleTime, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function acknowledgeTaskExceptionTest() + public function runTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - $scheduleTime = new Timestamp(); - try { - $client->acknowledgeTask($formattedName, $scheduleTime); + $client->runTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1354,81 +1202,68 @@ public function acknowledgeTaskExceptionTest() /** * @test */ - public function renewLeaseTest() + public function setIamPolicyTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Task(); - $expectedResponse->setName($name2); + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - $scheduleTime = new Timestamp(); - $leaseDuration = new Duration(); - - $response = $client->renewLease($formattedName, $scheduleTime, $leaseDuration); + $resource = 'resource-341064690'; + $policy = new Policy(); + $response = $client->setIamPolicy($resource, $policy); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/RenewLease', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - $actualValue = $actualRequestObject->getScheduleTime(); - - $this->assertProtobufEquals($scheduleTime, $actualValue); - $actualValue = $actualRequestObject->getLeaseDuration(); - - $this->assertProtobufEquals($leaseDuration, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function renewLeaseExceptionTest() + public function setIamPolicyExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - $scheduleTime = new Timestamp(); - $leaseDuration = new Duration(); - + $resource = 'resource-341064690'; + $policy = new Policy(); try { - $client->renewLease($formattedName, $scheduleTime, $leaseDuration); + $client->setIamPolicy($resource, $policy); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1437,76 +1272,64 @@ public function renewLeaseExceptionTest() /** * @test */ - public function cancelLeaseTest() + public function testIamPermissionsTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Task(); - $expectedResponse->setName($name2); + $expectedResponse = new TestIamPermissionsResponse(); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - $scheduleTime = new Timestamp(); - - $response = $client->cancelLease($formattedName, $scheduleTime); + $resource = 'resource-341064690'; + $permissions = []; + $response = $client->testIamPermissions($resource, $permissions); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/CancelLease', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - $actualValue = $actualRequestObject->getScheduleTime(); - - $this->assertProtobufEquals($scheduleTime, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function cancelLeaseExceptionTest() + public function testIamPermissionsExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - $scheduleTime = new Timestamp(); - + $resource = 'resource-341064690'; + $permissions = []; try { - $client->cancelLease($formattedName, $scheduleTime); + $client->testIamPermissions($resource, $permissions); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1515,71 +1338,62 @@ public function cancelLeaseExceptionTest() /** * @test */ - public function runTaskTest() + public function updateQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Task(); - $expectedResponse->setName($name2); + $name = 'name3373707'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $response = $client->runTask($formattedName); + $queue = new Queue(); + $response = $client->updateQueue($queue); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/RunTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta2.CloudTasks/UpdateQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getQueue(); + $this->assertProtobufEquals($queue, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function runTaskExceptionTest() + public function updateQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $queue = new Queue(); try { - $client->runTask($formattedName); + $client->updateQueue($queue); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); diff --git a/Tasks/tests/Unit/V2beta3/CloudTasksClientTest.php b/Tasks/tests/Unit/V2beta3/CloudTasksClientTest.php index 1b08e2d24a11..6272edded921 100644 --- a/Tasks/tests/Unit/V2beta3/CloudTasksClientTest.php +++ b/Tasks/tests/Unit/V2beta3/CloudTasksClientTest.php @@ -22,24 +22,26 @@ namespace Google\Cloud\Tasks\Tests\Unit\V2beta3; -use Google\Cloud\Tasks\V2beta3\CloudTasksClient; use Google\ApiCore\ApiException; + use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\Testing\GeneratedTest; use Google\ApiCore\Testing\MockTransport; + use Google\Cloud\Iam\V1\Policy; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; +use Google\Cloud\Tasks\V2beta3\CloudTasksClient; use Google\Cloud\Tasks\V2beta3\ListQueuesResponse; use Google\Cloud\Tasks\V2beta3\ListTasksResponse; use Google\Cloud\Tasks\V2beta3\Queue; use Google\Cloud\Tasks\V2beta3\Task; -use Google\Protobuf\Any; use Google\Protobuf\GPBEmpty; use Google\Rpc\Code; use stdClass; /** * @group tasks + * * @group gapic */ class CloudTasksClientTest extends GeneratedTest @@ -57,9 +59,7 @@ private function createTransport($deserialize = null) */ private function createCredentials() { - return $this->getMockBuilder(CredentialsWrapper::class) - ->disableOriginalConstructor() - ->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); } /** @@ -70,84 +70,72 @@ private function createClient(array $options = []) $options += [ 'credentials' => $this->createCredentials(), ]; - return new CloudTasksClient($options); } /** * @test */ - public function listQueuesTest() + public function createQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $queuesElement = new Queue(); - $queues = [$queuesElement]; - $expectedResponse = new ListQueuesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setQueues($queues); + $name = 'name3373707'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - - $response = $client->listQueues($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getQueues()[0], $resources[0]); - + $queue = new Queue(); + $response = $client->createQueue($formattedParent, $queue); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/ListQueues', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/CreateQueue', $actualFuncCall); $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getQueue(); + $this->assertProtobufEquals($queue, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function listQueuesExceptionTest() + public function createQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - + $queue = new Queue(); try { - $client->listQueues($formattedParent); + $client->createQueue($formattedParent, $queue); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -156,71 +144,70 @@ public function listQueuesExceptionTest() /** * @test */ - public function getQueueTest() + public function createTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name2); + $name = 'name3373707'; + $dispatchCount = 1217252086; + $responseCount = 424727441; + $expectedResponse = new Task(); + $expectedResponse->setName($name); + $expectedResponse->setDispatchCount($dispatchCount); + $expectedResponse->setResponseCount($responseCount); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->getQueue($formattedName); + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $task = new Task(); + $response = $client->createTask($formattedParent, $task); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/GetQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/CreateTask', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getTask(); + $this->assertProtobufEquals($task, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getQueueExceptionTest() + public function createTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $task = new Task(); try { - $client->getQueue($formattedName); + $client->createTask($formattedParent, $task); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -229,76 +216,59 @@ public function getQueueExceptionTest() /** * @test */ - public function createQueueTest() + public function deleteQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name); + $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - $queue = new Queue(); - - $response = $client->createQueue($formattedParent, $queue); - $this->assertEquals($expectedResponse, $response); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $client->deleteQueue($formattedName); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/CreateQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getQueue(); - - $this->assertProtobufEquals($queue, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/DeleteQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function createQueueExceptionTest() + public function deleteQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); - $queue = new Queue(); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->createQueue($formattedParent, $queue); + $client->deleteQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -307,71 +277,59 @@ public function createQueueExceptionTest() /** * @test */ - public function updateQueueTest() + public function deleteTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name); + $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); - // Mock request - $queue = new Queue(); - - $response = $client->updateQueue($queue); - $this->assertEquals($expectedResponse, $response); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $client->deleteTask($formattedName); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/UpdateQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getQueue(); - - $this->assertProtobufEquals($queue, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/DeleteTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function updateQueueExceptionTest() + public function deleteTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $queue = new Queue(); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); try { - $client->updateQueue($queue); + $client->deleteTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -380,68 +338,64 @@ public function updateQueueExceptionTest() /** * @test */ - public function deleteQueueTest() + public function getIamPolicyTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $client->deleteQueue($formattedName); + $resource = 'resource-341064690'; + $response = $client->getIamPolicy($resource); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/DeleteQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function deleteQueueExceptionTest() + public function getIamPolicyExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $resource = 'resource-341064690'; try { - $client->deleteQueue($formattedName); + $client->getIamPolicy($resource); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -450,71 +404,62 @@ public function deleteQueueExceptionTest() /** * @test */ - public function purgeQueueTest() + public function getQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; $expectedResponse = new Queue(); $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->purgeQueue($formattedName); + $response = $client->getQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/PurgeQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/GetQueue', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function purgeQueueExceptionTest() + public function getQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - try { - $client->purgeQueue($formattedName); + $client->getQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -523,71 +468,66 @@ public function purgeQueueExceptionTest() /** * @test */ - public function pauseQueueTest() + public function getTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); + $dispatchCount = 1217252086; + $responseCount = 424727441; + $expectedResponse = new Task(); $expectedResponse->setName($name2); + $expectedResponse->setDispatchCount($dispatchCount); + $expectedResponse->setResponseCount($responseCount); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->pauseQueue($formattedName); + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); + $response = $client->getTask($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/PauseQueue', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/GetTask', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function pauseQueueExceptionTest() + public function getTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); try { - $client->pauseQueue($formattedName); + $client->getTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -596,71 +536,70 @@ public function pauseQueueExceptionTest() /** * @test */ - public function resumeQueueTest() + public function listQueuesTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $expectedResponse = new Queue(); - $expectedResponse->setName($name2); + $nextPageToken = ''; + $queuesElement = new Queue(); + $queues = [ + $queuesElement, + ]; + $expectedResponse = new ListQueuesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setQueues($queues); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->resumeQueue($formattedName); - $this->assertEquals($expectedResponse, $response); + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); + $response = $client->listQueues($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getQueues()[0], $resources[0]); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/ResumeQueue', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/ListQueues', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function resumeQueueExceptionTest() + public function listQueuesExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); try { - $client->resumeQueue($formattedName); + $client->listQueues($formattedParent); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -669,73 +608,70 @@ public function resumeQueueExceptionTest() /** * @test */ - public function getIamPolicyTest() + public function listTasksTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); + $nextPageToken = ''; + $tasksElement = new Task(); + $tasks = [ + $tasksElement, + ]; + $expectedResponse = new ListTasksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTasks($tasks); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - - $response = $client->getIamPolicy($resource); - $this->assertEquals($expectedResponse, $response); + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->listTasks($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/GetIamPolicy', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/ListTasks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getIamPolicyExceptionTest() + public function listTasksExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - + $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->getIamPolicy($resource); + $client->listTasks($formattedParent); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -744,78 +680,62 @@ public function getIamPolicyExceptionTest() /** * @test */ - public function setIamPolicyTest() + public function pauseQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - - $response = $client->setIamPolicy($resource, $policy); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->pauseQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/SetIamPolicy', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPolicy(); - - $this->assertProtobufEquals($policy, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/PauseQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function setIamPolicyExceptionTest() + public function pauseQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->setIamPolicy($resource, $policy); + $client->pauseQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -824,74 +744,62 @@ public function setIamPolicyExceptionTest() /** * @test */ - public function testIamPermissionsTest() + public function purgeQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new TestIamPermissionsResponse(); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - - $response = $client->testIamPermissions($resource, $permissions); + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->purgeQueue($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/TestIamPermissions', $actualFuncCall); - - $actualValue = $actualRequestObject->getResource(); - - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPermissions(); - - $this->assertProtobufEquals($permissions, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/PurgeQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function testIamPermissionsExceptionTest() + public function purgeQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->testIamPermissions($resource, $permissions); + $client->purgeQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -900,77 +808,62 @@ public function testIamPermissionsExceptionTest() /** * @test */ - public function listTasksTest() + public function resumeQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $tasksElement = new Task(); - $tasks = [$tasksElement]; - $expectedResponse = new ListTasksResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setTasks($tasks); + $name2 = 'name2-1052831874'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name2); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - - $response = $client->listTasks($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); + $response = $client->resumeQueue($formattedName); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/ListTasks', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/ResumeQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function listTasksExceptionTest() + public function resumeQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - + $formattedName = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); try { - $client->listTasks($formattedParent); + $client->resumeQueue($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -979,13 +872,13 @@ public function listTasksExceptionTest() /** * @test */ - public function getTaskTest() + public function runTaskTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response $name2 = 'name2-1052831874'; $dispatchCount = 1217252086; @@ -995,59 +888,50 @@ public function getTaskTest() $expectedResponse->setDispatchCount($dispatchCount); $expectedResponse->setResponseCount($responseCount); $transport->addResponse($expectedResponse); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $response = $client->getTask($formattedName); + $response = $client->runTask($formattedName); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/GetTask', $actualFuncCall); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/RunTask', $actualFuncCall); $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function getTaskExceptionTest() + public function runTaskExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - try { - $client->getTask($formattedName); + $client->runTask($formattedName); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1056,80 +940,68 @@ public function getTaskExceptionTest() /** * @test */ - public function createTaskTest() + public function setIamPolicyTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $dispatchCount = 1217252086; - $responseCount = 424727441; - $expectedResponse = new Task(); - $expectedResponse->setName($name); - $expectedResponse->setDispatchCount($dispatchCount); - $expectedResponse->setResponseCount($responseCount); + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $task = new Task(); - - $response = $client->createTask($formattedParent, $task); + $resource = 'resource-341064690'; + $policy = new Policy(); + $response = $client->setIamPolicy($resource, $policy); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/CreateTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getParent(); - - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getTask(); - - $this->assertProtobufEquals($task, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function createTaskExceptionTest() + public function setIamPolicyExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedParent = $client->queueName('[PROJECT]', '[LOCATION]', '[QUEUE]'); - $task = new Task(); - + $resource = 'resource-341064690'; + $policy = new Policy(); try { - $client->createTask($formattedParent, $task); + $client->setIamPolicy($resource, $policy); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1138,68 +1010,64 @@ public function createTaskExceptionTest() /** * @test */ - public function deleteTaskTest() + public function testIamPermissionsTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); + $expectedResponse = new TestIamPermissionsResponse(); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $client->deleteTask($formattedName); + $resource = 'resource-341064690'; + $permissions = []; + $response = $client->testIamPermissions($resource, $permissions); + $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/DeleteTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function deleteTaskExceptionTest() + public function testIamPermissionsExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $resource = 'resource-341064690'; + $permissions = []; try { - $client->deleteTask($formattedName); + $client->testIamPermissions($resource, $permissions); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); @@ -1208,75 +1076,62 @@ public function deleteTaskExceptionTest() /** * @test */ - public function runTaskTest() + public function updateQueueTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $dispatchCount = 1217252086; - $responseCount = 424727441; - $expectedResponse = new Task(); - $expectedResponse->setName($name2); - $expectedResponse->setDispatchCount($dispatchCount); - $expectedResponse->setResponseCount($responseCount); + $name = 'name3373707'; + $expectedResponse = new Queue(); + $expectedResponse->setName($name); $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - - $response = $client->runTask($formattedName); + $queue = new Queue(); + $response = $client->updateQueue($queue); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/RunTask', $actualFuncCall); - - $actualValue = $actualRequestObject->getName(); - - $this->assertProtobufEquals($formattedName, $actualValue); - + $this->assertSame('/google.cloud.tasks.v2beta3.CloudTasks/UpdateQueue', $actualFuncCall); + $actualValue = $actualRequestObject->getQueue(); + $this->assertProtobufEquals($queue, $actualValue); $this->assertTrue($transport->isExhausted()); } /** * @test */ - public function runTaskExceptionTest() + public function updateQueueExceptionTest() { $transport = $this->createTransport(); - $client = $this->createClient(['transport' => $transport]); - + $client = $this->createClient([ + 'transport' => $transport, + ]); $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], ], JSON_PRETTY_PRINT); $transport->addResponse(null, $status); - // Mock request - $formattedName = $client->taskName('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]'); - + $queue = new Queue(); try { - $client->runTask($formattedName); + $client->updateQueue($queue); // If the $client method call did not throw, fail the test $this->fail('Expected an ApiException, but no exception was thrown.'); } catch (ApiException $ex) { $this->assertEquals($status->code, $ex->getCode()); $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); } - // Call popReceivedCalls to ensure the stub is exhausted $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted());