Delete a workflow using Python or Ruby.

Deletes a workflow using Python or Ruby.

Code sample

C#

Before trying this sample, follow the C# setup instructions in the Workflows quickstart using client libraries . For more information, see the Workflows C# API reference documentation .

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

  using 
  
  Google.Cloud.Workflows.Common.V1 
 
 ; 
 using 
  
  Google.Cloud.Workflows.V1 
 
 ; 
 using 
  
  Google.LongRunning 
 
 ; 
 using 
  
  Google.Protobuf.WellKnownTypes 
 
 ; 
 public 
  
 sealed 
  
 partial 
  
 class 
  
 GeneratedWorkflowsClientSnippets 
 { 
  
 /// <summary>Snippet for DeleteWorkflow</summary> 
  
 /// <remarks> 
  
 /// This snippet 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 as shown in 
  
 ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint. 
  
 /// </remarks> 
  
 public 
  
 void 
  
 DeleteWorkflowRequestObject 
 () 
  
 { 
  
 // Create client 
  
  WorkflowsClient 
 
  
 workflowsClient 
  
 = 
  
  WorkflowsClient 
 
 . 
  Create 
 
 (); 
  
 // Initialize request argument(s) 
  
  DeleteWorkflowRequest 
 
  
 request 
  
 = 
  
 new 
  
  DeleteWorkflowRequest 
 
  
 { 
  
 WorkflowName 
  
 = 
  
  WorkflowName 
 
 . 
  FromProjectLocationWorkflow 
 
 ( 
 "[PROJECT]" 
 , 
  
 "[LOCATION]" 
 , 
  
 "[WORKFLOW]" 
 ), 
  
 }; 
  
 // Make the request 
  
 Operation<Empty 
 , 
  
 OperationMetadata 
>  
 response 
  
 = 
  
 workflowsClient 
 . 
  DeleteWorkflow 
 
 ( 
 request 
 ); 
  
 // Poll until the returned long-running operation is complete 
  
 Operation<Empty 
 , 
  
 OperationMetadata 
>  
 completedResponse 
  
 = 
  
 response 
 . 
 PollUntilCompleted 
 (); 
  
 // Retrieve the operation result 
  
  Empty 
 
  
 result 
  
 = 
  
 completedResponse 
 . 
 Result 
 ; 
  
 // Or get the name of the operation 
  
 string 
  
 operationName 
  
 = 
  
 response 
 . 
 Name 
 ; 
  
 // This name can be stored, then the long-running operation retrieved later by name 
  
 Operation<Empty 
 , 
  
 OperationMetadata 
>  
 retrievedResponse 
  
 = 
  
 workflowsClient 
 . 
  PollOnceDeleteWorkflow 
 
 ( 
 operationName 
 ); 
  
 // Check if the retrieved long-running operation has completed 
  
 if 
  
 ( 
 retrievedResponse 
 . 
 IsCompleted 
 ) 
  
 { 
  
 // If it has completed, then access the result 
  
  Empty 
 
  
 retrievedResult 
  
 = 
  
 retrievedResponse 
 . 
 Result 
 ; 
  
 } 
  
 } 
 } 
 

Go

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

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

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 workflows 
  
 "cloud.google.com/go/workflows/apiv1" 
  
 workflowspb 
  
 "cloud.google.com/go/workflows/apiv1/workflowspb" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 // This snippet 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 as shown in: 
  
 //   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 
  
 c 
 , 
  
 err 
  
 := 
  
 workflows 
 . 
  NewClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 defer 
  
 c 
 . 
  Close 
 
 () 
  
 req 
  
 := 
  
& workflowspb 
 . 
 DeleteWorkflowRequest 
 { 
  
 // TODO: Fill request struct fields. 
  
 // See https://pkg.go.dev/cloud.google.com/go/workflows/apiv1/workflowspb#DeleteWorkflowRequest. 
  
 } 
  
 op 
 , 
  
 err 
  
 := 
  
 c 
 . 
 DeleteWorkflow 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 err 
  
 = 
  
 op 
 . 
 Wait 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

Java

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

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

  import 
  
 com.google.cloud.workflows.v1. DeleteWorkflowRequest 
 
 ; 
 import 
  
 com.google.cloud.workflows.v1. WorkflowName 
 
 ; 
 import 
  
 com.google.cloud.workflows.v1. WorkflowsClient 
 
 ; 
 import 
  
 com.google.protobuf. Empty 
 
 ; 
 public 
  
 class 
 SyncDeleteWorkflow 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 syncDeleteWorkflow 
 (); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 syncDeleteWorkflow 
 () 
  
 throws 
  
 Exception 
  
 { 
  
 // This snippet 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 as shown in 
  
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 
  
 try 
  
 ( 
  WorkflowsClient 
 
  
 workflowsClient 
  
 = 
  
  WorkflowsClient 
 
 . 
 create 
 ()) 
  
 { 
  
  DeleteWorkflowRequest 
 
  
 request 
  
 = 
  
  DeleteWorkflowRequest 
 
 . 
 newBuilder 
 () 
  
 . 
 setName 
 ( 
  WorkflowName 
 
 . 
 of 
 ( 
 "[PROJECT]" 
 , 
  
 "[LOCATION]" 
 , 
  
 "[WORKFLOW]" 
 ). 
 toString 
 ()) 
  
 . 
 build 
 (); 
  
 workflowsClient 
 . 
  deleteWorkflowAsync 
 
 ( 
 request 
 ). 
 get 
 (); 
  
 } 
  
 } 
 } 
 

Python

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

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

  # This snippet 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 as shown in: 
 #   https://googleapis.dev/python/google-api-core/latest/client_options.html 
 from 
  
 google.cloud 
  
 import 
  workflows 
 
_v1 def 
  
 sample_delete_workflow 
 (): 
 # Create a client 
 client 
 = 
 workflows_v1 
 . 
  WorkflowsClient 
 
 () 
 # Initialize request argument(s) 
 request 
 = 
 workflows_v1 
 . 
  DeleteWorkflowRequest 
 
 ( 
 name 
 = 
 "name_value" 
 , 
 ) 
 # Make the request 
 operation 
 = 
 client 
 . 
  delete_workflow 
 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Waiting for operation to complete..." 
 ) 
 response 
 = 
 operation 
 . 
 result 
 () 
 # Handle the response 
 print 
 ( 
 response 
 ) 
 

Ruby

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

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

  require 
  
 "google/cloud/workflows/v1" 
 ## 
 # Snippet for the delete_workflow call in the Workflows service 
 # 
 # This snippet 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 as shown in https://cloud.google.com/ruby/docs/reference. 
 # 
 # This is an auto-generated example demonstrating basic usage of 
 # Google::Cloud::Workflows::V1::Workflows::Client#delete_workflow. 
 # 
 def 
  
 delete_workflow 
  
 # Create a client object. The client can be reused for multiple calls. 
  
 client 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
 Workflows 
 :: 
 V1 
 :: 
 Workflows 
 :: 
 Client 
 . 
 new 
  
 # Create a request. To set request fields, pass in keyword arguments. 
  
 request 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
 Workflows 
 :: 
 V1 
 :: 
 DeleteWorkflowRequest 
 . 
 new 
  
 # Call the delete_workflow method. 
  
 result 
  
 = 
  
 client 
 . 
 delete_workflow 
  
 request 
  
 # The returned object is of type Gapic::Operation. You can use it to 
  
 # check the status of an operation, cancel it, or wait for results. 
  
 # Here is how to wait for a response. 
  
 result 
 . 
 wait_until_done! 
  
 timeout 
 : 
  
 60 
  
 if 
  
 result 
 . 
 response? 
  
 p 
  
 result 
 . 
 response 
  
 else 
  
 puts 
  
 "No response received." 
  
 end 
 end 
 

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: