Cancel a custom job

Cancels a custom job using the cancel_custom_job method.

Code sample

Node.js

Before trying this sample, follow the Node.js setup instructions in the Vertex AI quickstart using client libraries . For more information, see the Vertex AI Node.js API reference documentation .

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  /** 
 * TODO(developer): Uncomment these variables before running the sample.\ 
 */ 
 // const customJobId = 'YOUR_CUSTOM_JOB_ID'; 
 // const project = 'YOUR_PROJECT_ID'; 
 // const location = 'YOUR_PROJECT_LOCATION'; 
 // Imports the Google Cloud Job Service Client library 
 const 
  
 { 
 JobServiceClient 
 } 
  
 = 
  
 require 
 ( 
 ' @google-cloud/aiplatform 
' 
 ); 
 // Specifies the location of the api endpoint 
 const 
  
 clientOptions 
  
 = 
  
 { 
  
 apiEndpoint 
 : 
  
 'us-central1-aiplatform.googleapis.com' 
 , 
 }; 
 // Instantiates a client 
 const 
  
 jobServiceClient 
  
 = 
  
 new 
  
  JobServiceClient 
 
 ( 
 clientOptions 
 ); 
 async 
  
 function 
  
 cancelCustomJob 
 () 
  
 { 
  
 // Configure the name resource 
  
 const 
  
 name 
  
 = 
  
 jobServiceClient 
 . 
 customJobPath 
 ( 
 project 
 , 
  
 location 
 , 
  
 customJobId 
 ); 
  
 const 
  
 request 
  
 = 
  
 { 
  
 name 
 , 
  
 }; 
  
 // Cancel custom job request 
  
 const 
  
 [ 
 response 
 ] 
  
 = 
  
 await 
  
 jobServiceClient 
 . 
 cancelCustomJob 
 ( 
 request 
 ); 
  
 console 
 . 
 log 
 ( 
 'Cancel custom job response:\n' 
 , 
  
 response 
 ); 
 } 
 cancelCustomJob 
 (); 
 

Python

Before trying this sample, follow the Python setup instructions in the Vertex AI quickstart using client libraries . For more information, see the Vertex AI Python API reference documentation .

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  from 
  
 google.cloud 
  
 import 
 aiplatform 
 def 
  
 cancel_custom_job_sample 
 ( 
 project 
 : 
 str 
 , 
 custom_job_id 
 : 
 str 
 , 
 location 
 : 
 str 
 = 
 "us-central1" 
 , 
 api_endpoint 
 : 
 str 
 = 
 "us-central1-aiplatform.googleapis.com" 
 , 
 ): 
 # The AI Platform services require regional API endpoints. 
 client_options 
 = 
 { 
 "api_endpoint" 
 : 
 api_endpoint 
 } 
 # Initialize client that will be used to create and send requests. 
 # This client only needs to be created once, and can be reused for multiple requests. 
 client 
 = 
 aiplatform 
 . 
 gapic 
 . 
  JobServiceClient 
 
 ( 
 client_options 
 = 
 client_options 
 ) 
 name 
 = 
 client 
 . 
  custom_job_path 
 
 ( 
 project 
 = 
 project 
 , 
 location 
 = 
 location 
 , 
 custom_job 
 = 
 custom_job_id 
 ) 
 response 
 = 
 client 
 . 
  cancel_custom_job 
 
 ( 
 name 
 = 
 name 
 ) 
 print 
 ( 
 "response:" 
 , 
 response 
 ) 
 

What's next

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

Create a Mobile Website
View Site in Mobile | Classic
Share by: