Storage Batch Delete Job

Delete a storage batch operations job

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C++

For more information, see the Cloud Storage C++ API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  []( 
 google 
 :: 
 cloud 
 :: 
 storagebatchoperations_v1 
 :: 
 StorageBatchOperationsClient 
  
 client 
 , 
  
 std 
 :: 
 string 
  
 const 
&  
 project_id 
 , 
  
 std 
 :: 
 string 
  
 const 
&  
 job_id 
 ) 
  
 { 
  
 auto 
  
 const 
  
 parent 
  
 = 
  
 std 
 :: 
 string 
 { 
 "projects/" 
 } 
  
 + 
  
 project_id 
  
 + 
  
 "/locations/global" 
 ; 
  
 auto 
  
 const 
  
 name 
  
 = 
  
 parent 
  
 + 
  
 "/jobs/" 
  
 + 
  
 job_id 
 ; 
  
 auto 
  
 status 
  
 = 
  
 client 
 . 
 DeleteJob 
 ( 
 name 
 ); 
  
 if 
  
 ( 
 ! 
 status 
 . 
 ok 
 ()) 
  
 throw 
  
 status 
 ; 
  
 std 
 :: 
 cout 
 << 
 "Deleted job: " 
 << 
 name 
 << 
 " 
 \n 
 " 
 ; 
 } 
 

PHP

For more information, see the Cloud Storage PHP API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  use Google\Cloud\StorageBatchOperations\V1\Client\StorageBatchOperationsClient; 
 use Google\Cloud\StorageBatchOperations\V1\DeleteJobRequest; 
 /** 
 * Delete a batch job. 
 * 
 * @param string $projectId Your Google Cloud project ID. 
 *        (e.g. 'my-project-id') 
 * @param string $jobId A unique identifier for this job. 
 *        (e.g. '94d60cc1-2d95-41c5-b6e3-ff66cd3532d5') 
 */ 
 function delete_job(string $projectId, string $jobId): void 
 { 
 // Create a client. 
 $storageBatchOperationsClient = new StorageBatchOperationsClient(); 
 $parent = $storageBatchOperationsClient->locationName($projectId, 'global'); 
 $formattedName = $parent . '/jobs/' . $jobId; 
 $request = new DeleteJobRequest([ 
 'name' => $formattedName, 
 ]); 
 $storageBatchOperationsClient->deleteJob($request); 
 printf('Deleted job: %s', $formattedName); 
 } 
 

Ruby

For more information, see the Cloud Storage Ruby API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  require 
  
 "google/cloud/storage_batch_operations" 
 # Deletes a Storage Batch Operations job. 
 # 
 # @param project_id [String] The ID of your Google Cloud project. 
 # @param job_id [String] The ID of the Storage Batch Operations job to be deleted. 
 # 
 # @example 
 #   delete_job project_id: "your-project-id", job_id: "your-job-id" 
 # 
 def 
  
 delete_job 
  
 project_id 
 :, 
  
 job_id 
 : 
  
 client 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  StorageBatchOperations 
 
 . 
  storage_batch_operations 
 
  
 parent 
  
 = 
  
 "projects/ 
 #{ 
 project_id 
 } 
 /locations/global" 
  
 request 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  StorageBatchOperations 
 
 :: 
  V1 
 
 :: 
 DeleteJobRequest 
 . 
 new 
  
 name 
 : 
  
 " 
 #{ 
 parent 
 } 
 /jobs/ 
 #{ 
 job_id 
 } 
 " 
  
 begin 
  
 result 
  
 = 
  
 client 
 . 
 delete_job 
  
 request 
  
 message 
  
 = 
  
 "The 
 #{ 
 job_id 
 } 
 is deleted." 
  
 rescue 
  
 StandardError 
  
 # This error is thrown when the job is not deleted. 
  
 message 
  
 = 
  
 "Failed to delete job 
 #{ 
 job_id 
 } 
 . Error: 
 #{ 
 result 
 . 
 error 
 . 
 message 
 } 
 " 
  
 end 
  
 puts 
  
 message 
 end 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Design a Mobile Site
View Site in Mobile | Classic
Share by: