Criar um fluxo de trabalho usando Ruby

Cria um fluxo de trabalho usando Ruby.

Amostra de código

C#

Antes de testar essa amostra, siga as instruções de configuração para C# no Guia de início rápido do Workflows usando as bibliotecas de cliente. Para mais informações, consulte a documentação de referência da API Workflows para C# .

using Google.Api.Gax.ResourceNames;
using Google.Cloud.Workflows.V1;
using Google.LongRunning;

public sealed partial class GeneratedWorkflowsClientSnippets
{
    /// <summary>Snippet for CreateWorkflow</summary>
    /// <remarks>
    /// This snippet has been automatically generated for illustrative purposes only.
    /// It may require modifications to work in your environment.
    /// </remarks>
    public void CreateWorkflowRequestObject()
    {
        // Create client
        WorkflowsClient workflowsClient = WorkflowsClient.Create();
        // Initialize request argument(s)
        CreateWorkflowRequest request = new CreateWorkflowRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            Workflow = new Workflow(),
            WorkflowId = "",
        };
        // Make the request
        Operation<Workflow, OperationMetadata> response = workflowsClient.CreateWorkflow(request);

        // Poll until the returned long-running operation is complete
        Operation<Workflow, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Workflow 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<Workflow, OperationMetadata> retrievedResponse = workflowsClient.PollOnceCreateWorkflow(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Workflow retrievedResult = retrievedResponse.Result;
        }
    }
}

Python

Antes de testar essa amostra, siga as instruções de configuração para Python no Guia de início rápido do Workflows usando as bibliotecas de cliente. Para mais informações, consulte a documentação de referência da API Workflows para Python.

from google.cloud import workflows_v1

def sample_create_workflow():
    # Create a client
    client = workflows_v1.WorkflowsClient()

    # Initialize request argument(s)
    workflow = workflows_v1.Workflow()
    workflow.source_contents = "source_contents_value"

    request = workflows_v1.CreateWorkflowRequest(
        parent="parent_value",
        workflow=workflow,
        workflow_id="workflow_id_value",
    )

    # Make the request
    operation = client.create_workflow(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Antes de testar essa amostra, siga as instruções de configuração para Ruby no Guia de início rápido do Workflows usando bibliotecas de cliente. Para mais informações, consulte a documentação de referência da API Workflows para Ruby.

require "google/cloud/workflows/v1"

# 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::CreateWorkflowRequest.new

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

# The returned object is of type Gapic::Operation. You can use this
# object to check the status of an operation, cancel it, or wait
# for results. Here is how to block until completion:
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "Error!"
end

Próximas etapas

Para pesquisar e filtrar amostras de código de outros produtos do Google Cloud, consulte a amostra de navegador do Google Cloud.