Skip to content

Commit

Permalink
feat: promote cancel job API to GA (#8087)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 725297068
Source-Link: googleapis/googleapis@d383e2f
Source-Link: googleapis/googleapis-gen@0b95922
Copy-Tag: eyJwIjoiQmF0Y2gvLk93bEJvdC55YW1sIiwiaCI6IjBiOTU5MjJhMTlhZDBkNDg3NThiZDVmNTU5MjRjNDY3MDIxMjY4NzIifQ==
  • Loading branch information
gcf-owl-bot[bot] authored Feb 12, 2025
1 parent eab6523 commit d9db19e
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 29 deletions.
17 changes: 13 additions & 4 deletions Batch/metadata/V1/Batch.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Batch/metadata/V1/Job.php
Binary file not shown.
83 changes: 83 additions & 0 deletions Batch/samples/V1/BatchServiceClient/cancel_job.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START batch_v1_generated_BatchService_CancelJob_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Batch\V1\CancelJobRequest;
use Google\Cloud\Batch\V1\CancelJobResponse;
use Google\Cloud\Batch\V1\Client\BatchServiceClient;
use Google\Rpc\Status;

/**
* Cancel a Job.
*
* @param string $formattedName Job name. Please see
* {@see BatchServiceClient::jobName()} for help formatting this field.
*/
function cancel_job_sample(string $formattedName): void
{
// Create a client.
$batchServiceClient = new BatchServiceClient();

// Prepare the request message.
$request = (new CancelJobRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $batchServiceClient->cancelJob($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var CancelJobResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = BatchServiceClient::jobName('[PROJECT]', '[LOCATION]', '[JOB]');

cancel_job_sample($formattedName);
}
// [END batch_v1_generated_BatchService_CancelJob_sync]
155 changes: 155 additions & 0 deletions Batch/src/V1/CancelJobRequest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Batch/src/V1/CancelJobResponse.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Batch/src/V1/Client/BatchServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Google\ApiCore\Transport\TransportInterface;
use Google\ApiCore\ValidationException;
use Google\Auth\FetchAuthTokenInterface;
use Google\Cloud\Batch\V1\CancelJobRequest;
use Google\Cloud\Batch\V1\CreateJobRequest;
use Google\Cloud\Batch\V1\DeleteJobRequest;
use Google\Cloud\Batch\V1\GetJobRequest;
Expand Down Expand Up @@ -63,6 +64,7 @@
* name, and additionally a parseName method to extract the individual identifiers
* contained within formatted names that are returned by the API.
*
* @method PromiseInterface<OperationResponse> cancelJobAsync(CancelJobRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Job> createJobAsync(CreateJobRequest $request, array $optionalArgs = [])
* @method PromiseInterface<OperationResponse> deleteJobAsync(DeleteJobRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Job> getJobAsync(GetJobRequest $request, array $optionalArgs = [])
Expand Down Expand Up @@ -363,6 +365,32 @@ public function __call($method, $args)
return call_user_func_array([$this, 'startAsyncCall'], $args);
}

/**
* Cancel a Job.
*
* The async variant is {@see BatchServiceClient::cancelJobAsync()} .
*
* @example samples/V1/BatchServiceClient/cancel_job.php
*
* @param CancelJobRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return OperationResponse
*
* @throws ApiException Thrown if the API call fails.
*/
public function cancelJob(CancelJobRequest $request, array $callOptions = []): OperationResponse
{
return $this->startApiCall('CancelJob', $request, $callOptions)->wait();
}

/**
* Create a Job.
*
Expand Down
16 changes: 16 additions & 0 deletions Batch/src/V1/JobStatus/State.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9db19e

Please sign in to comment.