Python または Ruby を使用してワークフローを取得します。

Python または Ruby を使用してワークフローを取得します。

コードサンプル

C#

このサンプルを試す前に、クライアント ライブラリを使用した Workflows クイックスタートC# の手順に沿って設定を行ってください。 詳細については、Workflows C# API のリファレンス ドキュメントをご覧ください。

Workflows に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

using Google.Cloud.Workflows.Common.V1;
using Google.Cloud.Workflows.V1;

public sealed partial class GeneratedWorkflowsClientSnippets
{
    /// <summary>Snippet for GetWorkflow</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 GetWorkflowRequestObject()
    {
        // Create client
        WorkflowsClient workflowsClient = WorkflowsClient.Create();
        // Initialize request argument(s)
        GetWorkflowRequest request = new GetWorkflowRequest
        {
            WorkflowName = WorkflowName.FromProjectLocationWorkflow("[PROJECT]", "[LOCATION]", "[WORKFLOW]"),
            RevisionId = "",
        };
        // Make the request
        Workflow response = workflowsClient.GetWorkflow(request);
    }
}

Go

このサンプルを試す前に、クライアント ライブラリを使用した Workflows クイックスタートGo の手順に沿って設定を行ってください。 詳細については、Workflows Go API のリファレンス ドキュメントをご覧ください。

Workflows に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。


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.GetWorkflowRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/workflows/apiv1/workflowspb#GetWorkflowRequest.
	}
	resp, err := c.GetWorkflow(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

このサンプルを試す前に、クライアント ライブラリを使用した Workflows クイックスタートJava の手順に沿って設定を行ってください。 詳細については、Workflows Java API のリファレンス ドキュメントをご覧ください。

Workflows に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

import com.google.cloud.workflows.v1.GetWorkflowRequest;
import com.google.cloud.workflows.v1.Workflow;
import com.google.cloud.workflows.v1.WorkflowName;
import com.google.cloud.workflows.v1.WorkflowsClient;

public class SyncGetWorkflow {

  public static void main(String[] args) throws Exception {
    syncGetWorkflow();
  }

  public static void syncGetWorkflow() 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()) {
      GetWorkflowRequest request =
          GetWorkflowRequest.newBuilder()
              .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString())
              .setRevisionId("revisionId-1507445162")
              .build();
      Workflow response = workflowsClient.getWorkflow(request);
    }
  }
}

Python

このサンプルを試す前に、クライアント ライブラリを使用した Workflows クイックスタートPython の手順に沿って設定を行ってください。 詳細については、Workflows Python API のリファレンス ドキュメントをご覧ください。

Workflows に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

# 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_get_workflow():
    # Create a client
    client = workflows_v1.WorkflowsClient()

    # Initialize request argument(s)
    request = workflows_v1.GetWorkflowRequest(
        name="name_value",
    )

    # Make the request
    response = client.get_workflow(request=request)

    # Handle the response
    print(response)

Ruby

このサンプルを試す前に、クライアント ライブラリを使用した Workflows クイックスタートRuby の手順に沿って設定を行ってください。 詳細については、Workflows Ruby API のリファレンス ドキュメントをご覧ください。

Workflows に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

require "google/cloud/workflows/v1"

##
# Snippet for the get_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#get_workflow.
#
def get_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::GetWorkflowRequest.new

  # Call the get_workflow method.
  result = client.get_workflow request

  # The returned object is of type Google::Cloud::Workflows::V1::Workflow.
  p result
end

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。